How to make a timer appear the same for all players?

  1. What do you want to achieve? Keep it simple and clear!
    I am making a countdown timer. I want it to show the same time for all the players.
  2. What is the issue? Include screenshots / videos if possible!
    The timer works perfectly, but if a player joins when the timer is going, the time for the 2 players will be different. For example, it is intermission and 5 seconds for the 1st player but it is 10 for the other player.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Here is my script (it is inside the textlabel)

--scripted by anirudh851
--this handles rounds

function round()
	local target = workspace.GameSpawn.CFrame
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
			player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
		end
	end
	local t = 5
    while t > -1 do
		wait(1)
		local status = game.ReplicatedFirst.Status
		status.Value = "Time left: " .. t
    	script.Parent.Text = status.Value 
    	t = t - 1
		if t == -1 then
			wait(1)
			intermission()
    	end
	end
end
function intermission()
	local target = game.Workspace.Lobby.LobbySpawn.CFrame
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
			player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
		end
	end
	local it = 5
	while it > -1 do
		wait(1)
		local status = game.ReplicatedFirst.Status
		status.Value = "Intermission: " .. it
		script.Parent.Text = status.Value
		it = it - 1
		if it == -1 then
			wait(1)
			round()
		end
	end
end
round()

Location of the script in explorer is StarterGui > Timer(ScreenGui) > TextLabel > Script
All replies are appreciated! Thank you!

You can try to put it in the serverscriptservice and then send every second the time to the client with a RemoteEvent

RemoteEvent:FireAllClients(timing)

then put a local script in the gui that print the time on the player screen

What about server lag? Firing a RemoteEvent every second won’t lag the game? I dunno am just asking cuz I use RemoteEvents very less.

I tried to use it and I didn’t experience any lag, in case you could try calling it every 10 seconds and continue the countdown on the client, eliminating the differences every 10 seconds

Edit: it probably generates a bit of lag but it is almost imperceptible

1 Like

Any other way wihout RemoteEvents??? I usually use them for big tasks only, and I dont want an exploiter to break my game just because of a timer :grimacing:

sure, put a numberValue in the workspace and update it every second from the server
on the client put a numberValue.Changed and get the new value to print on the gui

3 Likes

Thanks a lot! I just hate RemoteEvents lol. Thank you once more!

1 Like