Textbox answer is not equal to value

Hello, once again. As explained before in my previous post, I want to make a math problem GUI.

The issue is now that when you have the correct number in the text box, it plays the wrong function. Which means every time I input a correct answer, it’s still wrong.

Example, math problem gives me a randomized math problem, the correct number is x. By inputting x, gives the wrong answer, although its correct.

Here’s the code:

local mathproblem1 = math.random(0,50)
local mathproblem2 = math.random(0,100)
local submitbutton = script.Parent.Parent.Submit
local mathproblemtext = script.Parent.MathProblem
local frame = script.Parent.Parent.Frame
local maxtime = script.Parent.MaxTime
local textbox = script.Parent.Parent.TextBox
local soundeffects = script.Parent.SoundEffects
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local LocalHumanoid = LocalCharacter:WaitForChild("Humanoid")

mathproblemtext.Text = "What is "..mathproblem1.." + "..mathproblem2.."?"
frame.Visible = true
textbox.Visible = true
submitbutton.Visible = true
maxtime.LocalScript.Enabled = true
soundeffects.Spawn:Play()

submitbutton.MouseButton1Up:Connect(function()
	wait(0.1)
	if textbox.Text == mathproblem1+mathproblem2 then
		maxtime.LocalScript.Enabled = false
		print("correct")
		soundeffects.Correct:Play()
		wait(1.5)
		script.Parent.Parent.Parent.MathProblem1:Destroy()
	end
	if textbox.Text ~= mathproblem1+mathproblem2 then
		maxtime.LocalScript.Enabled = false
		print("wrong")
		soundeffects.Wrong:Play()
		wait(1.5)
		LocalHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		script.Parent.Parent.Parent.MathProblem1:Destroy()
	end
end)
repeat
	wait(0.1)
	if maxtime.Value == 0 then
		script.Parent.timeover.Visible = true
		LocalHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		submitbutton.Visible = false
		textbox.Visible = false
		wait(3)
		script.Parent.Parent.Parent.MathProblem1:Destroy()
	end
until maxtime.Value == 0

Here is the explorer:
image_2023-02-12_162640917

Any help would be appreciated.

local mathproblem1 = math.random(0,50)
local mathproblem2 = math.random(0,100)
local submitbutton = script.Parent.Parent.Submit
local mathproblemtext = script.Parent.MathProblem
local frame = script.Parent.Parent.Frame
local maxtime = script.Parent.MaxTime
local textbox = script.Parent.Parent.TextBox
local soundeffects = script.Parent.SoundEffects
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalCharacter = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local LocalHumanoid = LocalCharacter:WaitForChild("Humanoid")

mathproblemtext.Text = "What is "..mathproblem1.." + "..mathproblem2.."?"
frame.Visible = true
textbox.Visible = true
submitbutton.Visible = true
maxtime.LocalScript.Enabled = true
soundeffects.Spawn:Play()

submitbutton.MouseButton1Up:Connect(function()
	wait(0.1)
	if tonumber(textbox.Text) == mathproblem1+mathproblem2 then
		maxtime.LocalScript.Enabled = false
		print("correct")
		soundeffects.Correct:Play()
		wait(1.5)
		script.Parent.Parent.Parent.MathProblem1:Destroy()
	end
	if tonumber(textbox.Text) ~= mathproblem1+mathproblem2 then
		maxtime.LocalScript.Enabled = false
		print("wrong")
		soundeffects.Wrong:Play()
		wait(1.5)
		LocalHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		script.Parent.Parent.Parent.MathProblem1:Destroy()
	end
end)
repeat
	wait(0.1)
	if maxtime.Value == 0 then
		script.Parent.timeover.Visible = true
		LocalHumanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		submitbutton.Visible = false
		textbox.Visible = false
		wait(3)
		script.Parent.Parent.Parent.MathProblem1:Destroy()
	end
until maxtime.Value == 0

Try this code “added tonumber function that converts the string to number”

Thank you so much :slight_smile:
Didn’t know this function existed, so I thank you for your work.

No problem, don’t forget that textbots are gives strings as result. Your function detects it as not equal because it is see the answer string == number. Tonumber converts the string to number.

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