Issue:
Counter doesn’t increase by 1 every time it loops through the timerEvent function for each individual player. Instead, it often doubles depending on how many people there are, only occurring if there is more than one player in the game.
Goal:
The counter increases by 1 on each client every time it loops through the timerEvent function.
Output during what is supposed to be round 2, counter is at 4 instead of 2:
Server Script:
local function gameLoop(plr)
suitChange()
for i, v in pairs(peopleList) do
local timerEvent = game:GetService("ReplicatedStorage").TimerEvent
timerEvent:FireClient(v)
end
end
local GameLoopEvent = game:GetService("ReplicatedStorage").GameLoopEvent
GameLoopEvent.OnServerEvent:Connect(function()
gameLoop()
end)
Client Script:
local counter = 1
local minutes = 0
local seconds = 6
--TimerFunc()
local timerEvent = game:GetService("ReplicatedStorage").TimerEvent
timerEvent.OnClientEvent:Connect(function()
local timer = script.Parent
if counter == 1 then
timer.Text = "Game Start"
wait(3)
end
print(counter)
timer.Text = "Round " .. counter
wait(3)
timer.Text = "3"
wait(1)
timer.Text = "2"
wait(1)
timer.Text = "1"
wait(1)
minutes = 0
seconds = 7
timerFunc()
timer.Text = "Round " .. counter .. " Over"
wait(2)
counter = counter + 1
timer.Text = "Find a cell & choose your suit"
wait(5)
minutes = 0
seconds = 15
local doorEvent = game:GetService("ReplicatedStorage").DoorEvent
doorEvent:FireServer()
timerFunc()
--local chosenEvent = game:GetService("ReplicatedStorage").ChosenEvent
--chosenEvent:FireServer()
timer.Text = "Doors Open"
wait(2)
for _, v in pairs(game.Workspace.Cells:GetChildren()) do
v.Transparency = 1
v.CanCollide = false
end
minutes = 0
seconds = 10
timerFunc()
for _, v in pairs(game.Workspace.Cells:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
minutes = 0
seconds = 10
timer.Text = "New Round Begins"
wait(3)
print("Loop finished")
local GameLoopEvent = game:GetService("ReplicatedStorage").GameLoopEvent
GameLoopEvent:FireServer()
end)