MessageBox.new Synchronous

Create a message box with your own title, text, icon, and buttons. Call Show to display it; the callback then receives the button the user pressed, or why the box closed.

Syntax
Luau
MessageBox.new(options: MessageBoxOptions?) -> MessageBox

Parameters

Function parameters
ParameterTypeDescription
optionsMessageBoxOptions?Optional table of settings. Every field is optional; see the argument fields below.

Argument fields

MessageBoxOptions fields
Luau
MessageBoxOptions = {
  Title: string?, Text: string?, Icon: string?, Buttons: {string}?,
  Duration: number?, Yield: boolean?, Callback: Function?
}
FieldTypeDescription
Titlestring?Text in the title bar. Defaults to an empty title.
Textstring?Text in the body. Defaults to empty.
Iconstring?A preset from MessageBox.Icons (Error, Question, Warning, or Information) or the path of an image in the workspace folder. A path that is not a file raises an error when the box is created.
Buttons{string}?Button labels in display order. Defaults to a single "Ok" button. The list must not be empty, and every label must be a string.
Durationnumber?Seconds before the box closes by itself and gives "TimedOut". Omit it to keep the box open until a choice is made.
Yieldboolean?Whether Show waits for the choice. Defaults to true.
CallbackFunction?Runs once with the choice string. OnChoice replaces it.

Returns

MessageBox

A MessageBox object with Show, Close, and OnChoice methods. Invalid options raise an error here, before anything is shown.

Usage notes

The callback receives one string: the pressed button's text, "Closed" when the user dismissed the box, "ForceClosed" after Close, "TimedOut" when Duration ran out, or "InternalError" when the box could not be shown. It runs once per box.

MessageBox.Icons holds the presets Error, Question, Warning, and Information. Up to three buttons sit along the bottom of the dialog; with more, they are listed one per row.

Example

Example
Luau
local box = MessageBox.new({
    Title = "Reset",
    Text = "Do you want to reset your character?",
    Icon = MessageBox.Icons.Question,
    Buttons = {"Reset", "Cancel"},
    Duration = 15,
    Callback = function(choice)
        if choice == "Reset" then
            game:GetService("Players").LocalPlayer.Character:BreakJoints()
        end
    end,
})
box:Show()