I am trying to make a timer on a teleporter that teleports you to a game and when others get in, the timer keeps the same rate, counting down by 1 per second.
However, when two or more people get in, the timer goes down rapidly subtracting 1 from itself in less than second, and does not even keep a smooth rate.
I know the issue here since it “removes” 1 from the timer starting from the second of each time the part is hit and so on, but I am not sure of how to script it in order to keep a steady rate, counting down by 1 per second even though more players enter the queue.
Here is a part of the code where the issue occurs:
script.Parent.ins.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
if not teleporting then
local char = hit.Parent
local player = game.Players:FindFirstChild(char.Name)
local inqueue = false
for i = 1, #list do
if list[i] == char.Name then
inqueue = true
end
end
if not inqueue then
if #list < 4 then if game.StarterPlayer.StarterCharacterScripts.Leave.Value.Value == false then
table.insert(list, char.Name)
char.PrimaryPart.CFrame = spawnTeleport.CFrame
updateGui()
leaveGuiEvent:FireClient(player)
lock:FireClient(player)
while timer > -1 and #list > 0 do
billboard.Frame.time.Text = timer
wait(1)
timer = timer - 1
if timer == 3 then billboard.Frame.Status.TextColor3 = Color3.fromRGB(0, 255, 0)
billboard.Frame.Status.Text = "READY"
end
if timer == 3 then baibai:FireClient(player)
end
if timer == 0 then billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
billboard.Frame.Status.BorderSizePixel = 2
billboard.Frame.Status.BorderColor3 = Color3.fromRGB(0, 0, 0)
billboard.Frame.Status.Text = "TELEPORTING..."
end
if timer == 0 then
script.Parent.Parent.door.close.tpval.Value = true
end
end
if #list == 0 then
timer = 15
billboard.Frame.time.Text = timer
end
teleportPlayers()
end
end
player.CharacterRemoving:Connect(function(character)
removeFromList(character)
end)
end
end
end
end)