Hey, so i’m having an issue with a timer system right now,
and i’m looking for help.
Issue Context
So basically what I did, is I made a function, with a countdown in it.
And when it hits 0, I called the function again so it keeps looping.
However, when the timer restarts, it goes 2x faster. (which is the issue)
EDIT : I just realised it speeds up when I die.
Script
local function StartGame(plr)
--// Variables
isTeleported = false
plr:WaitForChild("leaderstats"):WaitForChild("MapVoted").Value = ""
values:WaitForChild("GameLength").Value = defaultGameLength
values:WaitForChild("IntermissionLength").Value = 0
local character = plr.Character
local humRP = character:WaitForChild("HumanoidRootPart")
local plates = workspace:WaitForChild("Lobby"):WaitForChild("VotingPlace"):WaitForChild("Plates")
local blocksVotes = plates:WaitForChild("Blocks"):WaitForChild("VotesAmount")
local cityVotes = plates:WaitForChild("City"):WaitForChild("VotesAmount")
local forestVotes = plates:WaitForChild("Forest"):WaitForChild("VotesAmount")
local skylandsVotes = plates:WaitForChild("Skylands"):WaitForChild("VotesAmount")
--// Game Countdown
for count1 = values:WaitForChild("GameLength").Value, 0, -1 do
--// If it's not over
if values:WaitForChild("GameLength").Value > 0 then
values:WaitForChild("GameLength").Value -= 1
end
--// If it's over
if values:WaitForChild("GameLength").Value <= 0 then
values:WaitForChild("IntermissionLength").Value = defaultIntermissionLength
--// Intermission Countdown
for count2 = values:WaitForChild("IntermissionLength").Value, 0, -1 do
--// If it's not over
if values:WaitForChild("IntermissionLength").Value > 0 then
values:WaitForChild("IntermissionLength").Value -= 1
if not isTeleported then
isTeleported = true
humRP.CFrame = workspace:WaitForChild("Lobby"):WaitForChild("SpawnLocation").CFrame
end
end
--// If it's over
if values:WaitForChild("IntermissionLength").Value <= 0 then
values:WaitForChild("GameLength").Value = defaultGameLength
if blocksVotes.Value > cityVotes.Value and blocksVotes.Value > forestVotes.Value and blocksVotes.Value > skylandsVotes.Value then
chosenMap.Value = blocksVotes.Parent.Name
end
if cityVotes.Value > blocksVotes.Value and cityVotes.Value > forestVotes.Value and cityVotes.Value > skylandsVotes.Value then
chosenMap.Value = cityVotes.Parent.Name
end
if forestVotes.Value > cityVotes.Value and forestVotes.Value > blocksVotes.Value and forestVotes.Value > skylandsVotes.Value then
chosenMap.Value = forestVotes.Parent.Name
end
if skylandsVotes.Value > forestVotes.Value and skylandsVotes.Value > cityVotes.Value and skylandsVotes.Value > blocksVotes.Value then
chosenMap.Value = skylandsVotes.Parent.Name
end
humRP.CFrame = workspace:WaitForChild(chosenMap.Value):WaitForChild("TeamSpawns"):WaitForChild(plr.Team.Name).CFrame + Vector3.new(0,10,0)
remotes:WaitForChild("ClientReplicator"):FireAllClients()
break
end
wait(1)
end
break
end
wait(1)
end
end
task.spawn(function()
wait(2)
remotes:WaitForChild("StartGame").OnServerEvent:Connect(StartGame)
end)
Thanks for helping!