For some reason this script won't restart from the top or break when the wrong answer is given. It only ends when time runs out (after 20 seconds).
local p = game:GetService("Players")
local player = p.LocalPlayer
local pg = player.PlayerGui
local gui = pg:WaitForChild("ScreenGui")
local qnum = 1
local qtime = 20
local rs = game:GetService("ReplicatedStorage")
local questions = rs.Questions
local gametime = true
while gametime do
local questionset = questions:GetChildren()
local chosenquestion = questionset[math.random(1,#questionset)]
local a = chosenquestion.A
local b = chosenquestion.B
local c = chosenquestion.C
local d = chosenquestion.D
local correct = chosenquestion.Correct
local cg = gui.Frame.CorrectGuess
local boxa = gui.Frame.A
local boxb = gui.Frame.B
local boxc = gui.Frame.C
local boxd = gui.Frame.D
boxa.Visible = true
boxb.Visible = true
boxc.Visible = true
boxd.Visible = true
gui.Frame.Question.Visible = true
cg.Visible = false
gui.Frame.Question.Text = "Question ".. qnum .. ": ".. chosenquestion.Value
boxa.Text = "A) ".. a.Value
boxb.Text = "B) ".. b.Value
boxc.Text = "C) ".. c.Value
boxd.Text = "D) ".. d.Value
boxa.MouseButton1Down:Connect(function()
if correct.Value == boxa.Name then
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
cg.Text = "Correct!"
wait(3)
else
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
cg.Text = "Sorry! That's incorrect."
wait(3)
gametime = false
end
end)
boxb.MouseButton1Down:Connect(function()
if correct.Value == boxb.Name then
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
wait(3)
else
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
cg.Text = "Sorry! That's incorrect."
wait(3)
gametime = false
end
end)
boxc.MouseButton1Down:Connect(function()
if correct.Value == boxc.Name then
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
wait(3)
else
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
cg.Text = "Sorry! That's incorrect."
wait(3)
gametime = false
end
end)
boxd.MouseButton1Down:Connect(function()
if correct.Value == boxd.Name then
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
wait(3)
else
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
cg.Text = "Sorry! That's incorrect."
wait(3)
gametime = false
end
end)
if gui.Frame.Timer.Time.Value <= 0 then
gui.Frame.Question.Visible = false
boxa.Visible = false
boxb.Visible = false
boxc.Visible = false
boxd.Visible = false
cg.Visible = true
cg.Text = "Times Up!"
wait(3)
break
end
wait(20)
end
gui.Frame.Visible = false
I know it's a long script but bare with me. I just want this quiz game to get up and running so I can design better game aspects around it and make it look nice. If anyone knows how to restart a loop if a correct answer is given, your input would be greatly appreciated!

2 comments
Why do you have it all in a loop?
So it repeats the question-asking process