Problems with Preventing Unwanted Behaviours
This is a very simple script, that will basically act as a submission centre where I will eventually make a HTTP Request to perhaps post something later. However, I am having issues with the User Interface aspect (no errors, just it’s not working as intended). I would appreciate it if any of you could provide other work-arounds to ensure the expected behaviour is yielded at the end. This is the script below:
local debounce = false
local main = script.Parent.Parent
local q1 = main.One
local err = main.Error
local q2 = main.Two
local nxt = main.Next
local back = main.Back
function clicked()
if q1.Visible then -- Question 1: Complaintant(s)
if #q1.Content.Text > 0 then
if err.Visible then
err.Visible = false
end
q2.Visible = true
q1.Visible = false
back.Visible = true
script.Parent.Position = UDim2.new(0.525, 0,0.814, 0)
else -- error handling
if debounce then return end
err.Text = script.Parent.Parent.Error.Text .. " You need to input a complaintant(s)."
err.Visible = true
debounce = true
for i = 0, 3,1 do wait(1) end
err.Visible = false
debounce = false
end
end
if q2.Visible then
if q2.Button1.Font == Enum.Font.SourceSansBold or q2.Button2.Font == Enum.Font.SourceSansBold or q2.Button3.Font == Enum.Font.SourceSansBold then
if q2.Button1.Font == Enum.Font.SourceSansBold then
q2.Expungement.Visible = true
q2.Visible = false
if err.Visible then
err.Visible = false
end
end
if q2.Button2.Font == Enum.Font.SourceSansBold then
if err.Visible then
err.Visible = false
end
end
else
if debounce then return end
err.Text = err.Text .. " You need to select a Type of Case."
err.Visible = true
debounce = true
for i = 0, 3,1 do wait(1) end
err.Visible = false
debounce = false
end
end
end
script.Parent.MouseButton1Click:Connect(clicked)
Extra Information
Current Outcomes:
- What I’m doing is checking if the Next button is clicked with a function called clicked.
- Check if a GuiObject is Visible and continue onward from there.
- For the second if statement:
if q2.Visible then
This is where my issues happen because, what I don’t want to happen is for the client to be shown an error before they have even clicked on anything. To show what I mean by this, here is a video that will pretty much sum up everything:
As you should be able to see, before anything happens, an error is prompted. However, what I want to happen is to somehow end the function after an if statement. An example (the comment):
function clicked()
if q1.Visible then -- Question 1: Complaintant(s)
if #q1.Content.Text > 0 then
if err.Visible then
err.Visible = false
end
q2.Visible = true
q1.Visible = false
back.Visible = true
script.Parent.Position = UDim2.new(0.525, 0,0.814, 0)
else -- error handling
if debounce then return end
err.Text = script.Parent.Parent.Error.Text .. " You need to input a complaintant(s)."
err.Visible = true
debounce = true
for i = 0, 3,1 do wait(1) end
err.Visible = false
debounce = false
-- end the function here until called again
end
end