Timer going faster for each player

Here again with another Script Problem.

What should do: Player Join Queue > Timer starts from 30 to 0 > Another Code
What it does: Player Join Queue> Timer starts from 30 to 0 > Another Player Joins> Timer goes faster> Another code

Basically more players join the queue the more the timer goes fast and i’m searching a way to make it static and only subtracting 1/sec

Started = false

script.Parent.Players.Changed:Connect(function()
	if script.Parent.Players.Value >= 1 then
		
			Started = true
		if Started == true then
			repeat
			script.Parent.Time.Value = script.Parent.Time.Value -1
            Started = false
			wait(1)
			until script.Parent.Players.Value < 1 or script.Parent.Time.Value <= 0
		end

You’re running your loop every time the number of players changes.

You want to run your loop once.

One way might be to keep track of the previous number of players, and only start your timer if that changes:

local lastPlayers = 0

script.Parent.Players.Changed:Connect(function(newValue)
    if lastPlayers == 0 and newValue > 0 then
        repeat
            script.Parent.Time.Value = script.Parent.Time.Value - 1
            wait(1)
        until script.Parent.Players.Value < 1 or script.Parent.Time.Value <= 0
    end
    
    lastPlayers = newValue
end)
4 Likes

That newValue what should be?
I tried but still going faster

If you really want to make it go faster per player, I would change the “wait(1)” part, I would make it more like this:

Started = false

script.Parent.Players.Changed:Connect(function()
if script.Parent.Players.Value >= 1 then

		Started = true
	if Started == true then
		repeat
		script.Parent.Time.Value = script.Parent.Time.Value -1
                    Started = false
		wait(2^-(script.Parent.Players.Value-1)) --This will make it so that it speeds up x2 for each new player after the first player. 
		until script.Parent.Players.Value < 1 or script.Parent.Time.Value <= 0
	end

This is how I would try to handle the problem (if you’re trying to make it speed up for however many players there are in the que). If it doesn’t work please tell me so I can re-look at it.

It already goes faster, i want to make it go -1/s even if there are 10 players in queue :sweat_smile:

Sorry I’m a bit new to devforum lol.

Oh you want it to always go at wait(1), my bad lol.

Whoop I meant, ugh nvm I am saying things wrong today.

Actually when more than one player joins the queue the repeat loop starts more time and make it go 30-29-28-27 in like 1Sec, i’m searching for something that make the repeat loop start when ther is 1 player and does not start again

Everytime that the value of “Players” changes, it is running a repeat loop, you want to make it so it only runs the repeat loop once.

No problem, i appreciate your help man

Exactly, so no matter how many players are in the queue the timer will be always 30sec and then teleport them all

Hope I got it right this time lol.

Sorry made a mistake:

Started = false

script.Parent.Players.Changed:Connect(function()

if script.Parent.Players.Value >= 1 then
if Started == false then
Started = true
repeat
script.Parent.Time.Value = script.Parent.Time.Value -1
wait(1)
until script.Parent.Players.Value < 1 or script.Parent.Time.Value <= 0
end
else
Started = false
end

Select the entire script and click con </> this will help you in future

Started = false

script.Parent.Players.Changed:Connect(function()
    if script.Parent.Players.Value >= 1 then
        if Started == false then
            Started = true
            repeat
            script.Parent.Time.Value = script.Parent.Time.Value -1
            wait(1)
            until script.Parent.Players.Value < 1 or script.Parent.Time.Value <= 0
        end
    else
        Started = false
    end

end)

Still messed up one part lol, but thank you.

Not working but i guess is because i have copied it wrong, here is the full script
Actually when another player joins it fires the teleport

local function cancel()
	script.Parent.Time.Value = 30
end

Started = false

script.Parent.Players.Changed:Connect(function()
	if script.Parent.Players.Value >= 1 then
		if Started == false then
			Started = true	
			repeat
			script.Parent.Time.Value = script.Parent.Time.Value -1
			wait(1)
			until script.Parent.Players.Value < 1 or script.Parent.Time.Value <= 0
		end
			
			
        local tp = game:GetService("TeleportService")
        local server = tp:ReserveServer(5496511414)
		for i,v in pairs(script.Parent.Waiting:GetChildren()) do
			if game.Players:FindFirstChild(v.Name) then
				
				local Players = game:GetService("Players")

				print("For now working...")
				local plr = Players:FindFirstChild(v.Name)
				print(plr)
				print("Teleport ", plr, "To ", server )

				
				tp:TeleportToPrivateServer(5496511414, server, {plr})
				
				
				v:Destroy()
			end
		end
		cancel()
	else
	Started = false
	cancel()
end
end)

What part of it exactly isn’t working though…? Are there any errors in the output?

The script is working fine but it fires the teleport when a second player joins the queue