Can anyone help me make a 5 minute timer that resets every 5 minutes and kills players when it in finished

Hello! I’m Chxrlvie and I’m currently developing an obby game.
I need a 5 minute timer on the screen that resets when it hits zero, and also when it hits zero it kills all the players in the server to make the obby more of a challenge that you only have 5 minutes to complete, can anyone help me with a timer? (UI on screen that resets every 5 minutes and kills players)

1 Like

Hello! Scripting Support isn’t for getting full scripts but I can show you a way to do this.

For the server-sided countdown, you could use a for-loop.

A Script in ServerScriptService

Example:

local seconds = 300 --300 seconds = 5 minutes

for i = seconds, 0, -1 do
wait(1)

You could then set a value in ReplicatedStorage to the current second so that the client later can get it:

game.ReplicatedStorage.Time.Value = i

Then, to check if the countdown has finished, you can simply add if:

if i == 0 then

And also another for-loop to get all players and respawn them:

for i = 1, #game.Players:GetChildren() do
	player = game.Players:GetChildren()[i]
				
	player:LoadCharacter()
end

Since you want it to loop you can add a while-loop in the beginning. Here is the full script:

local seconds = 300

while true do
	for i = seconds, 0, -1 do
		
		wait(1)
		game.ReplicatedStorage.Time.Value = i
		
		if i == 0 then
			for i = 1, #game.Players:GetChildren() do
				player = game.Players:GetChildren()[i]
				
				player:LoadCharacter()
			end
		end
	end
end

To make the client-sided countdown you can just get the value like this:

A LocalScript in StarterGui

text = script.Parent

function change()
	script.Parent.Text = game.ReplicatedStorage.Time.Value
end

game.ReplicatedStorage.Time.Changed:Connect(function()
	change()
end)

change()

I hope this helps!

2 Likes

You can use this:

function KillPlayersAfter(Time)
    delay(Time, function()
        local players = game.Players:GetPlayers()
        for i, v in next, players, 1 do
            --You can have another way to check if they completed an obby
            --It's up to you
            if player.ObbyCompleted.Value then continue end
            
            --Kill the player
            (v.Character or v.CharacterAdded:Wait()):BreakJoints()
        end
    end)
end
    
--Check if it is time for an obby
if obbyTime then
    KillPlayersAfter(300) -- Time in seconds
end

2 Likes

I don’t understand what you mean by set a value in replicated storage

He means create a IntValue called Time and place it in ReplicatedStorage

1 Like