So, I’m making a quiz game sort of like the impossible quiz and I’m trying to make a question that you wait five seconds to move on to the next question. but I made a script, and it doesn’t seem to work.
local currentQuestion = script.Parent
local nextQuestion = currentQuestion.Parent.Question39
if currentQuestion.Visible == true then
wait(5)
currentQuestion.Visible = false
nextQuestion.Visible = true
end
ScreenGuis don’t have Visible as a valid property. To enable or disable a ScreenGui, you have to use the Enabled property instead:
local currentQuestion = script.Parent
local nextQuestion = currentQuestion.Parent.Question39
currentQuestion:GetPropertyChangedSignal("Enabled"):Connect(function()
if currentQuestion.Enabled == true then
task.wait(5)
currentQuestion.Enabled = false
nextQuestion.Enabled = true -- assuming this is a ScreenGui as well, correct me if I'm wrong
end
end
Run the code again and see if it works again maybe? I remove the delay so you can see instant changes
local currentQuestion = script.Parent
local nextQuestion = currentQuestion.Parent.Question39
currentQuestion:GetPropertyChangedSignal("Visible"):Connect(function(...: any)
currentQuestion.Visible = not currentQuestion.Visible
nextQuestion.Visible = not nextQuestion.Visible
end)
to fix that error you either use debounce or disconnect the connection.
an example with the debounce should look like
local currentQuestion = script.Parent
local nextQuestion = currentQuestion.Parent.Question39
local db = false
currentQuestion:GetPropertyChangedSignal("Visible"):Connect(function(...: any)
if db == true then return end
db = true -- debounce
currentQuestion.Visible = not currentQuestion.Visible
nextQuestion.Visible = not nextQuestion.Visible
task.delay(1, function() -- setting it back to false
db = false
end)
end)
llocal currentQuestion = script.Parent
local nextQuestion = currentQuestion.Parent.Question39
local db = false
currentQuestion:GetPropertyChangedSignal("Visible"):Connect(function(...: any)
if db then return end
db = true -- debounce
task.wait(5)
currentQuestion.Visible = not currentQuestion.Visible
nextQuestion.Visible = not nextQuestion.Visible
task.wait(.5)
db = false
end)
Edit: Don’t create new threads so use the updated code.