This is the whole script that is used in the gui
local questions = {
{“Red”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},1},
{“Orange”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},2},
{“Yellow”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},3},
{“Green”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},4},
{“Blue”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},5},
{“Purple”,{“Red”,“Orange”,“Yellow”,“Green”,“Blue”,“Purple”},6}
}
local numberCorrect = 0
local NumberOfQuestions = 6
local function finish()
local percentCorrect = math.floor(numberCorrect/NumberOfQuestions * 100)
--DISABLES THE GUI
game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.TestEnd.Visible = true
game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.TestEnd.Number.Text = percentCorrect
end
local Question, Answers, CorrectAnswer
local function changeQuestion()
-- load question
local TempQuestionNumber = math.random(1,#questions)
local QuestionData = questions[TempQuestionNumber]
Question, Answers, CorrectAnswer = unpack(QuestionData)
-- Set all frames visibility to false
local UI_objs=script.Parent.Frame:GetChildren()
for i,obj in pairs(UI_objs) do
if (obj:IsA('Frame')) then
obj.Visible=false
end
end
-- Set the corresponding frame's visibility to true if it exists
if script.Parent.Frame:FindFirstChild(Answers[CorrectAnswer]) then
script.Parent.Frame:FindFirstChild(Answers[CorrectAnswer]).Visible=true
end
table.remove(questions,TempQuestionNumber)
end
local function answer(name)
if string.match(name, Answers[CorrectAnswer]) then -- If button name contains answer than mark correct; works within this specific context, may not work for another
numberCorrect = numberCorrect+1
end
if #questions<=0 then -- If all questions are taken then finish test
finish()
else
changeQuestion() -- Otherwise change question
end
end
-- Connect all buttons to answer function
local UI_objs=script.Parent.Frame:GetChildren()
for i,obj in pairs(UI_objs) do
if (obj:IsA('TextButton')) then
obj.MouseButton1Click:Connect(function () answer(obj.Name) end)
end
end
changeQuestion()