Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local changeTimerEvent = game.ReplicatedStorage:WaitForChild('ChangeTimerEvent')
- -- Player start timer event that runs character function
- function startTimerPlayer(player)
- player.CharacterAdded:Connect(startTimer)
- end
- game.Players.PlayerAdded:Connect(startTimerPlayer)
- function startTimer(character)
- -- Variables and the initial event call
- local timer = 0
- local alive = true
- local player = game.Players:GetPlayerFromCharacter(character)
- changeTimerEvent:FireClient(player, timer)
- -- Function called when character dies
- local function onDeath()
- -- Best time leaderstats value
- local bestTime = player:FindFirstChild('leaderstats'):FindFirstChild('Best Time')
- -- If timer is better than best timechange best time
- if timer > bestTime.Value then
- bestTime.Value = timer
- end
- -- Reset variables
- timer = 0
- alive = false
- end
- character:WaitForChild('Humanoid').Died:Connect(onDeath)
- wait(1)
- -- Timer loop that increases while player is alive
- while alive do
- timer = timer + 1
- changeTimerEvent:FireClient(player, timer)
- wait(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement