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

Does somebody know why doesn't this script use inputs correctly?

Asked by 6 years ago

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

1
Can you please be more in depth? What happens when you click submit? Does it error? Does nothing happen? shayner32 478 — 6y
0
Nothing happens JoshTheDarkOne 0 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

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.

0
Please Note: I have tested his script, it does work with this fix. ^~^ Arti_BLOX 58 — 6y
Ad

Answer this question