I want to make a custom dialog chooser system.
The problem is, my script for some reason returns nil.
I tried multiple ways, like making it run a function instead, but that does not work.
Here is my server code in a required ModuleScript:
local clientResponse = dialogEvent:FireClient(player, "Yes", "No")
if clientResponse == "OptionOne" then
option1()
elseif clientResponse == "OptionTwo" then
option2()
elseif clientResponse == "Error: required argument missing" then
errorFunc()
end
And here is my dialogHandler in a LocalScript:
local opt1Clicked = false
local opt2Clicked = false
game.ReplicatedStorage:WaitForChild("dialogEvent").OnClientEvent:Connect(function(option1: string, option2: string)
script.Parent.Enabled = true
opt1Clicked = false
opt2Clicked = false
script.Parent.option1.Visible = true
script.Parent.option2.Visible = true
if option1 == nil then return "Error: required argument missing" end
--if option2 == nil then script.Parent.option2.Visible = false else script.Parent.option2.Text = option2 end
script.Parent.option1.Text = option1
script.Parent.option2.Text = option2
local opt1Connection = script.Parent.option1.MouseButton1Click:Connect(function()
opt1Clicked = true
opt2Clicked = false
end)
local opt2Connection = script.Parent.option2.MouseButton1Click:Connect(function()
opt2Clicked = true
opt1Clicked = false
end)
repeat wait() until opt1Clicked or opt2Clicked
if opt1Clicked then
opt1Connection:Disconnect()
opt2Connection:Disconnect()
wait(.25)
script.Parent.Enabled = false
return "OptionOne"
elseif opt2Clicked then
opt1Connection:Disconnect()
opt2Connection:Disconnect()
wait(.25)
script.Parent.Enabled = false
return "OptionTwo"
end
end)