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
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.