local textvalue = Player.PlayerGui.QNA.Question.Value
while game.ReplicatedStorage.SendQuestion.Changed do
if not (textvalue == "Correct!") or (textvalue == "Incorrect, the correct answer is "..script.Parent.AnswerInText.Value) then
if time == 0 then
Player.PlayerGui:WaitForChild("QNA").AnswerGui.Frame.Timer.Text = "Times Up!"
break
else
Player.PlayerGui:WaitForChild("QNA").AnswerGui.Frame.Timer.Text = ("Answer in "..tostring(time).." seconds..")
time = time -1
end
end
task.wait(1)
end
end)
In this script when textvalue == “Correct” the script works and not running loop again.
But when textvalue == "Incorrect, the correct answer is "…script.Parent.AnswerInText.Value) the script
still running the loop. I don’t know why it works when its equal to this.
I believe you need to use the :Wait() function to make it work properly because you are only accessing the event property and not actually connecting to it in anyway:
while game.ReplicatedStorage.SendQuestion.Changed:Wait() do
--Your code here
end
You would need to put the timer in a different thread and then cancel the SendQuestion event connection when the timer is over. You are currently combing the timer with the handling of the answer. You should probably separate them. Also the statement should be:
if textvalue ~= "Correct!" and textvalue ~= "Incorrect, the correct answer is "..script.Parent.AnswerInText.Value then
--Your code here
end