Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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


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

2 comments

1

Can you please be more in depth? What happens when you click submit? Does it error? Does nothing happen?

0

Nothing happens

1 answer

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.

1 comment

0

Please Note: I have tested his script, it does work with this fix. ^~^

This discussion is preserved as it was. New answers, comments, and votes are closed.