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!
put the timer in the player and you don't need a local script for any of that.