Not working "If Not" script

Hello, i wrote a script like that;

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.

not has to be incorporated for both sides of or

Your amended code would look like this:

if not (textvalue == "Correct!") or not (textvalue == "Incorrect, the correct answer is "..script.Parent.AnswerInText.Value) then
1 Like

This made booth not working, now it just keep working even if it’s correct.

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

I hope this helps!

1 Like

When i make :Wait the timer won’t work.

Do you have any idea why it didn’t work?

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

I hope this works in some way!

1 Like

Thank you! It works right now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.