local question = script.Parent.Question local answerbox = script.Parent.AnswerBox local submit = script.Parent.Submit local number1 = math.random(1,12) local number2 = math.random(1,12) local answer = number1 * number2 local answerstring = tostring(answer) question.Text = "What is "..number1.." X "..number2.." = " submit.MouseButton1Click:connect(function() if answerbox == answerstring then question.Text = "Well done!" wait(3) question.Text = "Submit" local number1 = math.random(1,12) local number2 = math.random(1,12) local answer = number1 * number2 local answerstring = tostring(answer) question.Text = "What is "..number1.." X "..number2.." = " end end) end)
I am making a maths game and I need someone to help me with the inputs
There's 3 problems in this script.
1) The if statement on line 14 is checking if the textbox answerbox is equal to answerstring. Your textbox is an instance, so you cant compare it to a string. Replace this with answerbox.Text instead.
2) Once the question is answered, you declared new variables in your if statement to replace your older ones. However, these variables are local, and is seperate to your variables declared in lines 5, 6, 8 and 9.
3) There's a random end) in line 27.
Your script should look like this:
local question = script.Parent.Parent.Question local answerbox = script.Parent.Parent.AnswerBox local submit = script.Parent local number1 = math.random(1,12) local number2 = math.random(1,12) local answer = number1 * number2 local answerstring = tostring(answer) question.Text = "What is "..number1.." X "..number2.." = " submit.MouseButton1Click:connect(function() if answerbox.Text == answerstring then question.Text = "Well done!" wait(3) question.Text = "Submit" number1 = math.random(1,12) number2 = math.random(1,12) answer = number1 * number2 answerstring = tostring(answer) question.Text = "What is "..number1.." X "..number2.." = " end end)
Hope this helped.