OneQuiz and TwoQuiz are not in PlayerGui
My bad, use WaitForChild
local button = script.Parent
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local QuizScreen1 = PlayerGui:WaitForChild("OneQuiz"):WaitForChild("QuizScreen1")
local QuizScreen2 = PlayerGui:WaitForChild("TwoQuiz"):WaitForChild("QuizScreen2")
local QuizScreens = {
QuizScreen1,
QuizScreen2
}
button.MouseButton1Click:Connect(function()
print("Clicked")
button.Parent.Visible = false
print("Main Menu Not There")
task.wait()
local quiz = QuizScreens[math.random(1, #QuizScreens)]
task.wait()
print("Randomized")
quiz.Visible = true
print("Visible")
end)
1 Like
Maybe this?:
local button = script.Parent
local QuizScreensFolder = button.Parent.Parent.QuizScreens
local buttonParent = button.Parent.Parent
local QuizScreens = {}
for _, child in ipairs(QuizScreensFolder:GetChildren()) do
if child:IsA("Frame") then
table.insert(QuizScreens, child)
end
end
button.MouseButton1Click:Connect(function()
buttonParent.Enabled = false
for _, quizScreen in ipairs(QuizScreens) do
quizScreen.Visible = false
end
local randomIndex = math.random(1, #QuizScreens)
QuizScreens[randomIndex].Visible = true
end)
That is a good idea. Using a ScreenGui and storing frames in it, then using a script to loop through it id better than manually typing it out.
As a side note, math.random(1, 5)
, for example, is the same as math.random(5)
.
I was self-taught by youtube videos and ChatGPT, so apologies.
Its called “the more you know”
I didn’t know about it until much later on, either
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.