Server Sided Timer

I have this timer script that is server sided but want it to be able to support more than 1 person per server, but when there is multiple people in the server the timer only works for 1 person … How would i go about keeping the timer server sided but also so that people each have their own timer that works ? :slight_smile:

local plr
local timer

game.Players.PlayerAdded:Connect(function(player)
	timer = player.PlayerGui:WaitForChild("ScreenGui").TextLabel
	print(player.Parent)
	print(player)
end)

for i, v in pairs(game.Players:GetPlayers()) do 
	v.Character.Humanoid.Died:Connect(function()
		timer = v.PlayerGui:WaitForChild("ScreenGui").TextLabel
	end)
end

local mill = 00
local sec = 00
local min = 00

local start = false

local function timerStart()
	while start == true do 
		wait(0.0455)
		mill = mill + 5
		if mill >= 100 then
			mill = mill - 100
			sec = sec + 1
		end
		if sec >= 60 then
			sec = sec - 60
			min = min + 1 
		end
		if mill <= 9 then 
			timer.Text = min..":"..sec..":".."0"..mill
		end
		if sec <= 9 then 
			timer.Text = min..":".."0"..sec..":"..mill
		end
		if min <= 9 then 
			timer.Text = "0"..min..":"..sec..":"..mill
		end
		if mill <= 9 and sec <= 9 then
			timer.Text = min..":".."0"..sec..":".."0"..mill
		end
		if mill <= 9 and min <= 9 then
			timer.Text = "0"..min..":"..sec..":".."0"..mill
		end
		if min<= 9 and sec <= 9 then
			timer.Text = "0"..min..":".."0"..sec..":"..mill
		end
		if min <= 9 and sec <= 9 and mill <= 9 then
			timer.Text = "0"..min..":".."0"..sec..":".."0"..mill
		end
	end
end

workspace.Start1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if timer.Text ~= "00:00:00" then
			mill = 00
			sec = 00
			min = 00
		end
		if timer.TextTransparency == 1 then
			timer.TextTransparency = 0
		end
		start = true
		timer.TextColor3 = Color3.new(0.172549, 0.92549, 0.262745)
		timer.TextTransparency = 0
		
		timerStart()

		workspace.Start1.CanTouch = false
		workspace.Finish1.CanTouch = true
		wait(3)
		end
end)

workspace.Finish1.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then
		timer.TextColor3 = Color3.new(1, 0.576471, 0.294118)
		start = false
		workspace.Start1.CanTouch = true
		workspace.Finish1.CanTouch = false
	end
	wait(3)
end)

workspace.Death.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then
		workspace.Start1.CanTouch = true
		workspace.Finish1.CanTouch = false
		start = false
		timer.TextTransparency = 1
	end
	wait(3)
end)

Why do you need the timer to be server sided, and why don’t you just use os.time? If you need milliseconds, you can still use os.time but run a for loop from 0 to 100 each second, and then after a second has passed, check the os.time again and use that.

I heard that if the timer is client sided if the player lags it might also lag the timer a little bit

That’s possible, but os.time wouldn’t lag like that, it doesn’t do milliseconds though. In that case, you may just need to cope with the fact that lag could slow down the timer. You could also use os.clock, however in my experience that timer can be substantially misconstrued, especially as a result of lag, since it’s the CPU clock.

ok thanks a lot, i guess ill make the timer local, shouldn’t be too much of a problem i guess, also thanks for the tips ! :slight_smile:

oh also would exploiters be able to change the timers time if i make it local ?

Probably, yes. A server sided timer would probably be better in that scenario, if you’re worried about exploiters. Or, you could have a timer on the client to show the client, and independently run a timer on the server aswell.