What I am currently working on is this timer for my “guess the state” game. What happens is that when the player is given a question, they must submit the correct answer to get a new question and reset the timer. If the timer reaches zero, they will be given a new question to answer and the timer resets.
So as you can clearly see, the problem is that I am trying to reset a for loop (timer) with a press of a GUI button, but with no success.
Here’s the code:
--Timer--
local function timer()
while true do
for i = TimerLabelValue, 1, -1 do
TimerLabel.Text = i
wait(1)
end
local NewStatePickNumber = math.random(1, 5)
StatePickNumber = NewStatePickNumber
chooseState()
end
end
--Button function--
SubmitButton.MouseButton1Down:Connect(function()
if StatePickNumber == 1 and AnswerBox.Text == "Olympia" then --Washington Correct
CorrectSound:Play()
AnswerBox.Text = nil
elseif StatePickNumber == 1 and AnswerBox.Text ~= "Olympia" then --Washington NOT Correct
IncorrectSound:Play()
elseif StatePickNumber == 2 and AnswerBox.Text == "Salem" then --Oregeon Correct
CorrectSound:Play()
elseif StatePickNumber == 2 and AnswerBox.Text ~= "Salem" then --Oregeon NOT Correct
IncorrectSound:Play()
elseif StatePickNumber == 3 and AnswerBox.Text == "Sacramento" then --California Correct
CorrectSound:Play()
elseif StatePickNumber == 3 and AnswerBox.Text ~= "Sacramento" then --California NOT Correct
IncorrectSound:Play()
elseif StatePickNumber == 4 and AnswerBox.Text == "Carson City" then --Nevada Correct
CorrectSound:Play()
elseif StatePickNumber == 4 and AnswerBox.Text ~= "Carson City" then --Nevada NOT Correct
IncorrectSound:Play()
elseif StatePickNumber == 5 and AnswerBox.Text == "Boise" then --Idaho Correct
CorrectSound:Play()
elseif StatePickNumber == 5 and AnswerBox.Text ~= "Boise" then --Idaho NOT Correct
IncorrectSound:Play()
end
local NewStatePickNumber = math.random(1,10)
correctValue = true
StatePickNumber = NewStatePickNumber
chooseState() --Makes new question
end)