Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a timer that works independently of other players?

I am making a speedrun game and I want a timer that shows on the leaderboard that keeps track of how long a player has been doing the speedrun and the timer will end once the player has reached the end and touched a block. This is the script I have right now but the issue is that once any player touches the block, the timer ends for everyone. How can I make it individual to the player and will be non-exploitable?

Local Script Inside StarterPlayerScripts

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local addTimer = ReplicatedStorage:WaitForChild("Timer")

local clock = true

-- Fire the remote event
while clock do
	wait(1)
	addTimer:FireServer()
	local endblock = game.Workspace.TeleportBricks.Level1
	endblock.Touched:Connect(function(hit)
		clock = false
	end)
end

Server Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local addTimer = ReplicatedStorage:WaitForChild("Timer")

local function AddTime(player)
	local Time = player.leaderstats.RunTime
	print(player.Name .. " has been running for " .. Time.Value .. " seconds")
	Time.Value += 1
end

addTimer.OnServerEvent:Connect(AddTime)

Thanks!

1 answer

put the timer in the player and you don't need a local script for any of that.

1 comment

0

Could you elaborate on this? I’m pretty new to roblox scripting and I’m not sure what you mean.

This discussion is preserved as it was. New answers, comments, and votes are closed.