I am a small roblox developper and I ran into a problem. Right now, I made a localScript for a quiz game that asks question from data and the user must answer the question in a certain amount of time (Like shown on the image)
The problem I am trying to solve is that for now, the game only works for the individual that starts de quiz, not the others
But I have no idea how to modify my script so that everyone has the same questions at the same time.
I tried to learn the RemoteEvent strategy but it never worked after 5 hours of trying again and again
Here is the code of the Quiz right now
local trivialevel1 = {
{ --Math
question = "What is the mathematical constant π (pi) approximately equal to?",
answers = {"2.718","3.142","1.618","0.577"},
correctanswer = 2,
category = "Math"
},
{
question = "What is the result of multiplying any number by zero?",
answers = {"1","The number itself","Zero","Infinity"},
correctanswer = 3,
category = "Math"
},
{
question = "What is the term for a polygon with five sides?",
answers = {"Hexagon","Octagon","Pentagon","Heptagon"},
correctanswer = 3,
category = "Math"
},
{
question = "What is the value of the square root of 144?",
answers = {"144","16","9","12"},
correctanswer = 4,
category = "Math"
},
{
question = "What is the sum of all angles in a triangle?",
answers = {"270","180","360","90"},
correctanswer = 2,
category = "Math"
},
{
question = "If a number is divisible by 2 and 3, what other number is it also divisible by?",
answers = {"4","8","6","5"},
correctanswer = 3,
category = "Math"
},
{ --Sports
question = "Which country won the most recent FIFA World Cup in 2022?",
answers = {"Brazil","Germany","France","Argentina"},
correctanswer = 4,
category = "Sports"
},
{
question = "Which sport is associated with the term 'slam dunk'?",
answers = {"Soccer","Tennis","Baseball","Basketball"},
correctanswer = 4,
category = "Sports"
},
{
question = "In baseball, how many strikes constitute a strikeout for a batter?",
answers = {"4","2","3","1"},
correctanswer = 3,
category = "Sports"
},
{ --Geography
question = "What is the world's largest ocean?",
answers = {"Atlantic Ocean","Idian Ocean","Artic Ocean","Pacific Ocean"},
correctanswer = 4,
category = "Geography"
},
{
question = "What is the capital city of Japan?",
answers = {"Beijing","Seoul","Tokyo","Bangkok"},
correctanswer = 3,
category = "Geography"
},
{
question = "What is the largest country in Africa by land area?",
answers = {"Nigeria","Egypt","South Africa","Algeria"},
correctanswer = 4,
category = "Geography"
}
}
local trivialevel2 = {
{ --Math
question = "Which of the following is the smallest prime number?",
answers = {"3","2","1","4"},
correctanswer = 2,
category = "Math"
},
{
question = "In the equation E=mc², what does the 'c' represent?",
answers = {"Speed of light", "Planck constant","Gravitational constant","Electric charge"},
correctanswer = 1,
category = "Math"
},
{ --Sports
question = "Which athelete is often referred to as The Fastest Man on Earth?",
answers = {"Michael Phelps","Usain Bolt","LeBron James","Cristiano Ronaldo"},
correctanswer = 2,
category = "Sports"
},
{
question = "Which Winter Olympic sport involves atheletes sliding down a frozen track on a sled?",
answers = {"Ice hockey","Curling","Ski jumping","Skeleton"},
correctanswer = 4,
category = "Sports"
},
{
question = "In American football, how many points is a safety worth? ",
answers = {"2","3","6","1"},
correctanswer = 1,
category = "Sports"
},
{
question = "Which tennis player has won the most Wimbledon titles in the men's singles category?",
answers = {"Andre Agassi","Rafael Nadal","Roger Federer","Novak Djokovic"},
correctanswer = 3,
category = "Sports"
},
{ --Geography
question = "Which continent is home to the Sahara Desert, the largest hot desert in the world?",
answers = {"South America","Africa","Asia","Australia"},
correctanswer = 2,
category = "Geography"
},
{
question = "Which river is the longest in the world?",
answers = {"Nile","Amazon","Yangtze","Mississippi"},
correctanswer = 1,
category = "Geography"
},
{
question = "Which European country is known as the 'Land of Fire and Ice' due to its volcanic activity and glaciers?",
answers = {"Sweden","Finland","Iceland","Norway"},
correctanswer = 3,
category = "Geography"
},
{ --Food
question = "Which Italian pasta is shaped like small rice grains?",
answers = {"Penne","Fusilli","Orzo","Linguine"},
correctanswer = 3,
category = "Food"
},
}
local trivialevel3 = {
{ --Math
question = "Which famous mathematician is known for his work on the theory of relativity?",
answers = {"Isaac Newton","Galileo Galilei","Albert Einstein","Archimedes"},
correctanswer = 3,
category = "Math"
},
{ --Sports
question = "What is the national sport of Japan?",
answers = {"Sumo wrestling","Judo","Karate","Kendo"},
correctanswer = 1,
category = "Sports"
},
{
question = "Which gold major is held at Augusta National Golf Club?",
answers = {"The Open Championship","The PGA Championship","The Masters Tournament","The U.S Open"},
correctanswer = 3,
category = "Sports"
},
{
question = "Which country is known for dominating the sport of cricket and is considered a cricket powerhouse?",
answers = {"England","Australia","South Africa","India"},
correctanswer = 4,
category = "Sports"
},
{ --Geography
question = "The Great Barrier Reef, one of the world's most famous coral reef systems, is located off the coast of which country?",
answers = {"Brazil","Australia","Indonesia","Mexico"},
correctanswer = 2,
category = "Geography"
},
{
question = "Which mountain range stretches across seven countries in South America?",
answers = {"Rocky Mountains","Andes","Alps","Himalayas"},
correctanswer = 2,
category = "Geography"
},
{
question = "Which famous canal connects the Mediterranean Sea to the Red Sea?",
answers = {"Suez Canal","Panama Canal","Kiel Canal","Corinth Canal"},
correctanswer = 1,
category = "Geography"
},
{
question = "What is the smallest independent country in the world, both in terms of area and population?",
answers = {"Monaco","Vatican City","Liechtenstein","San Marino"},
correctanswer = 2,
category = "Geography"
},
}
local question = script.Parent.Parent.Parent.Quiz.Frame.Question
local answer1 = script.Parent.Parent.Parent.Quiz.Frame.Answer1
local answer2 = script.Parent.Parent.Parent.Quiz.Frame.Answer2
local answer3 = script.Parent.Parent.Parent.Quiz.Frame.Answer3
local answer4 = script.Parent.Parent.Parent.Quiz.Frame.Answer4
local category = script.Parent.Parent.Parent.Quiz.Frame.Category
local currentquestionindex = 1
local selectedIndex = 0
local buttons = {answer1,answer2,answer3,answer4}
local player = game.Players.LocalPlayer
--TIMER
local timer = script.Parent.Parent.Parent.Quiz.Frame.Timer
local countdownDuration = 10
local currentCountdown = countdownDuration
local isCounting = false
local function updateTimer()
while isCounting and currentCountdown > 0 do
timer.Text = tostring(currentCountdown)
wait(1)
currentCountdown = currentCountdown - 1
end
timer.Text = "Time's up!"
end
local function startCountdown()
isCounting = true
currentCountdown = countdownDuration
updateTimer()
end
local function stopCountdown()
isCounting = false
end
local function shuffle(array)
local n = #array
for i = n, 2, -1 do
local j = math.random(i)
array[i], array[j] = array[j], array[i]
end
end
local function displayQuestionlevel1(index)
local questionData = trivialevel1[index]
question.Text = questionData.question
end
local function displayQuestionlevel2(index)
local questionData = trivialevel2[index]
question.Text = questionData.question
end
local function displayQuestionlevel3(index)
local questionData = trivialevel3[index]
question.Text = questionData.question
end
local function displayAnswerslevel1(index)
local answersdata = trivialevel1[index]
answer1.Text = answersdata.answers[1]
answer2.Text = answersdata.answers[2]
answer3.Text = answersdata.answers[3]
answer4.Text = answersdata.answers[4]
end
local function displayAnswerslevel2(index)
local answersdata = trivialevel2[index]
answer1.Text = answersdata.answers[1]
answer2.Text = answersdata.answers[2]
answer3.Text = answersdata.answers[3]
answer4.Text = answersdata.answers[4]
end
local function displayAnswerslevel3(index)
local answersdata = trivialevel3[index]
answer1.Text = answersdata.answers[1]
answer2.Text = answersdata.answers[2]
answer3.Text = answersdata.answers[3]
answer4.Text = answersdata.answers[4]
end
local function displayCategorylevel1(index)
local categorydata = trivialevel1[index]
category.Text = categorydata.category
end
local function displayCategorylevel2(index)
local categorydata = trivialevel2[index]
category.Text = categorydata.category
end
local function displayCategorylevel3(index)
local categorydata = trivialevel3[index]
category.Text = categorydata.category
end
local function addCoins(amount)
player:WaitForChild("leaderstats"):WaitForChild("Coins").Value = player.leaderstats.Coins.Value + amount
end
script.Parent.Parent.Parent.Quiz.bouton.MouseButton1Click:Connect(function()
local error1 = script.Parent.Parent.Parent.Quiz.Frame.Error1
local error2 = script.Parent.Parent.Parent.Quiz.Frame.Error2
local error3 = script.Parent.Parent.Parent.Quiz.Frame.Error3
error1.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
error2.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
error3.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
script.Parent.Parent.Parent.Quiz.Frame.Visible = true
local questionsdone = 0
local errorCount = 0
while(questionsdone < 7) do
script.Parent.Parent.Parent.Quiz.Frame.Answer1.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer2.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer3.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer4.BackgroundColor3 = Color3.fromRGB(255,122,69)
shuffle(trivialevel1)
displayQuestionlevel1(currentquestionindex)
displayAnswerslevel1(currentquestionindex)
displayCategorylevel1(currentquestionindex)
startCountdown()
if selectedIndex == trivialevel1[currentquestionindex].correctanswer then
buttons[selectedIndex].BackgroundColor3 = Color3.fromRGB(35, 255, 19)
addCoins(10)
else
buttons[trivialevel1[currentquestionindex].correctanswer].BackgroundColor3 = Color3.fromRGB(35, 255, 19)
buttons[selectedIndex].BackgroundColor3 = Color3.fromRGB(255,0,0)
errorCount = errorCount + 1
if errorCount == 1 then
error1.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
elseif errorCount == 2 then
error2.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
elseif errorCount == 3 then
error3.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
-- Code pour le personnage qui meurt ici (ajoutez votre propre logique)
game.Players.LocalPlayer.Character:BreakJoints()
end
end
wait(5)
questionsdone = questionsdone + 1
end
while(questionsdone < 14) do
script.Parent.Parent.Parent.Quiz.Frame.Answer1.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer2.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer3.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer4.BackgroundColor3 = Color3.fromRGB(255,122,69)
shuffle(trivialevel2)
displayQuestionlevel2(currentquestionindex)
displayAnswerslevel2(currentquestionindex)
displayCategorylevel2(currentquestionindex)
startCountdown()
if selectedIndex == trivialevel2[currentquestionindex].correctanswer then
buttons[selectedIndex].BackgroundColor3 = Color3.fromRGB(35, 255, 19)
addCoins(10)
else
buttons[trivialevel2[currentquestionindex].correctanswer].BackgroundColor3 = Color3.fromRGB(35, 255, 19)
buttons[selectedIndex].BackgroundColor3 = Color3.fromRGB(255,0,0)
errorCount = errorCount + 1
if errorCount == 1 then
error1.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
elseif errorCount == 2 then
error2.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
elseif errorCount == 3 then
error3.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
-- Code pour le personnage qui meurt ici (ajoutez votre propre logique)
game.Players.LocalPlayer.Character:BreakJoints()
end
end
wait(5)
questionsdone = questionsdone + 1
end
while(nil) do
script.Parent.Parent.Parent.Quiz.Frame.Answer1.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer2.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer3.BackgroundColor3 = Color3.fromRGB(255,122,69)
script.Parent.Parent.Parent.Quiz.Frame.Answer4.BackgroundColor3 = Color3.fromRGB(255,122,69)
shuffle(trivialevel3)
displayQuestionlevel3(currentquestionindex)
displayAnswerslevel3(currentquestionindex)
displayCategorylevel3(currentquestionindex)
startCountdown()
if selectedIndex == trivialevel3[currentquestionindex].correctanswer then
buttons[selectedIndex].BackgroundColor3 = Color3.fromRGB(35, 255, 19)
addCoins(10)
else
buttons[trivialevel3[currentquestionindex].correctanswer].BackgroundColor3 = Color3.fromRGB(35, 255, 19)
buttons[selectedIndex].BackgroundColor3 = Color3.fromRGB(255,0,0)
errorCount = errorCount + 1
if errorCount == 1 then
error1.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
elseif errorCount == 2 then
error2.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
elseif errorCount == 3 then
error3.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Rouge
-- Code pour le personnage qui meurt ici (ajoutez votre propre logique)
game.Players.LocalPlayer.Character:BreakJoints()
end
end
wait(5)
questionsdone = questionsdone + 1
end
end)
script.Parent.Parent.Parent.Quiz.Frame.Answer1.MouseButton1Click:Connect(function()
selectedIndex = 1
script.Parent.Parent.Parent.Quiz.Frame.Answer1.BackgroundColor3 = Color3.fromRGB(143,68,39)
script.Parent.Parent.Parent.Quiz.Frame.Answer1.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer2.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer3.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer4.Active = false
end)
script.Parent.Parent.Parent.Quiz.Frame.Answer2.MouseButton1Click:Connect(function()
selectedIndex = 2
script.Parent.Parent.Parent.Quiz.Frame.Answer2.BackgroundColor3 = Color3.fromRGB(143,68,39)
script.Parent.Parent.Parent.Quiz.Frame.Answer1.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer2.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer3.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer4.Active = false
end)
script.Parent.Parent.Parent.Quiz.Frame.Answer3.MouseButton1Click:Connect(function()
selectedIndex = 3
script.Parent.Parent.Parent.Quiz.Frame.Answer3.BackgroundColor3 = Color3.fromRGB(143,68,39)
script.Parent.Parent.Parent.Quiz.Frame.Answer1.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer2.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer3.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer4.Active = false
end)
script.Parent.Parent.Parent.Quiz.Frame.Answer4.MouseButton1Click:Connect(function()
selectedIndex = 4
script.Parent.Parent.Parent.Quiz.Frame.Answer4.BackgroundColor3 = Color3.fromRGB(143,68,39)
script.Parent.Parent.Parent.Quiz.Frame.Answer1.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer2.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer3.Active = false
script.Parent.Parent.Parent.Quiz.Frame.Answer4.Active = false
end)
Thank you for any help you guys can give me :)
I am available to give you any other information needed to solve my problem