Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED] How do I check for the correct answer to an equation?

Asked by 5 years ago
Edited 5 years ago

Hi, I'm making a script where the player gets 2 random values at the top of the screen, and has to do addition to find the correct answer. I've set up the value part but I've noticed that the script doesnt recognize the correct answers. I expected it to work by doing something like if T.Text == sum then but that doesn't seem to be working. How do I fix this?

local T = script.Parent
local Question1 = (math.random(1,10))
local Q1 = script.Parent.Parent.QuestionBox1
local p1 = (Question1)
Q1.Text = Question1


local Question2 = (math.random(1,10))
local Q2 = script.Parent.Parent.QuestionBox2
local p2 = (Question2)
Q2.Text = Question2



T.FocusLost:Connect(function(enterPressed)
if enterPressed then
local sum = (p1 + p2)
print(T.Text)
print(sum)
if T.Text == sum then
    print("Correct")
end
end
end)
0
is T.Text a string or a number? Benbebop 1049 — 5y
0
It's the string text of a parent textbox jensar141215 157 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I converted the string of T.Text using the tostring() command.

Ad

Answer this question