I am trying to make a gui that quizzes you

I am trying to make a gui that quizzes you but for some reason when it chooses the number 2 nothing happens

here is the script

local random = math.random(1,2)
local WhatQuestion = script.Parent.Parent.WhatQuestion
local Answer = script.Parent.Parent.Answer
if random == 1 then
WhatQuestion.Value = “What Is The 9 + 10?”
wait(10)
if Answer.Text == “21” then
correct()
elseif Answer.Text == “21” == false then
incorrect()
elseif random == 2 then
WhatQuestion.Value = “What Is The Reason Why This Script Won’t Work?”
wait(10)
if Answer.Text == “Idk” then
correct()
elseif Answer.Text == “Idk” == false then
incorrect()
I have tried searching but I will continue to search just in case

please and thank you, Davey boi

1 Like
do you mean
local random = math.random(1,2)
local WhatQuestion = script.Parent.Parent.WhatQuestion
local Answer = script.Parent.Parent.Answer
if random == 1 then
WhatQuestion.Value = “What Is The 9 + 10?”
wait(10)
if Answer.Text == “21” then
correct()
elseif Answer.Text == “21” == false then
incorrect()
elseif random == 2 then
WhatQuestion.Value = “What Is The Reason Why This Script Won’t Work?”
wait(10)
if Answer.Text == “Idk” then
correct()
elseif Answer.Text == “Idk” == false then
incorrect()

edits

local random = math.random(1,2)
local WhatQuestion = script.Parent.Parent.WhatQuestion
local Answer = script.Parent.Parent.Answer
if random == 1 then
WhatQuestion.Value = “What Is The 9 + 10?”
wait(10)
if Answer.Text == “21” then
correct()
elseif Answer.Text ~= “21” then
incorrect()
elseif random == 2 then
WhatQuestion.Value = “What Is The Reason Why This Script Won’t Work?”
wait(10)
if Answer.Text == “Idk” then
correct()
elseif Answer.Text ~= “Idk” then
incorrect()

First of all, please format your code next time.

Secondly, the code can be simplified, to be even shorter. Like this:

local random = math.random(2) -- the number of questions in the list
local WhatQuestion = script.Parent.Parent.WhatQuestion
local Answer = script.Parent.Parent.Answer

local questions = {"What is 9 + 10?","What is the reason why this script won't work?"}
local answers = {"21", "Idk"} -- these are the questions answers, in the same order as the questions

WhatQuestion.Value = questions[random] -- chosen question

task.wait(10)

if answers[random].lower() == Answer.Text.lower() then -- checks if the lowercase versions match
	
	corret()
	
else
	
	incorrect()
	
end

when it chooses 2 the question doesn’t appear
I also think its because of elseif random == 2 then

local random = math.random(1,2)
local WhatQuestion = script.Parent.Parent:WaitForChild("WhatQuestion")
local Answer = script.Parent.Parent:WaitForChild("Answer")

if random == 1 then
	WhatQuestion.Value = "What Is The 9 + 10?"
	task.wait(10)
	if Answer.Text == "21" then
		print("Correct!")
	elseif Answer.Text ~= "21" then
		print("Incorrect!")
	end
elseif random == 2 then
	WhatQuestion.Value = "What Is The Reason Why This Script Won’t Work?"
	task.wait(10)
	if Answer.Text == "Idk" then
		print("Correct!")
	elseif Answer.Text ~= "Idk" then
		print("Incorrect!")
	end
end
1 Like