If statement doesn't work

Hello, i’ve been doing math equations script and I ran into a problem that if statement doesn’t run at all. I’ve debugged it and found out that the script works before the if statement and then stops.

local AnswerTextbox = script.Parent
local Answer = AnswerTextbox.Parent:GetAttribute("Answer")
local RS = game:GetService("ReplicatedStorage")
local Events = RS.Events

AnswerTextbox:GetPropertyChangedSignal("Text"):Connect(function()
	AnswerTextbox.Text = AnswerTextbox.Text:gsub('%D+', '');
end)

AnswerTextbox.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		print("enter pressed") -- prints
		if AnswerTextbox.Text == Answer then
			print("someone typed "..AnswerTextbox.Text.. " as their answer!") -- doesn't print
			print("the answer is: "..Answer.."!") -- doesn't print
		end
	end
end)

Any help will be appreciated!

%D+ only keeps numbers but the data type is still string. If Answer is a number, perhaps you need to convert AnswerTextbox.Text into a number for comparison.

1 Like

I added

tostring(Answer)

And it worked! Thank you.

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