← Back to Racing Scripts

Time Tracking Scripts

Two scripts work together to track lap times!

Your Custom Settings

CanCollide off, Transparency 0.5

TimeScript - Local Script (StarterGui)

This script detects when the car touches the StartLapCheckpoint (starts the timer) and the LapCheckpoint (stops the timer). Create both parts in Workspace with CanCollide off and adjust Transparency. Also create "StartTimeEvent" and "EndTimeEvent" RemoteEvents in ReplicatedStorage.

local repStore = game:GetService("ReplicatedStorage")
local startTimeEvent = repStore:WaitForChild("StartTimeEvent")
local endTimeEvent = repStore:WaitForChild("EndTimeEvent")
local startOfLap = game.:WaitForChild("StartLapCheckpoint")
local endOfLap = game.Workspace:WaitForChild("LapCheckpoint")
startOfLap.:Connect(function(hit)
    if hit.Parent == game.Workspace.myCar then
        startTimeEvent:()
    end
end)
endOfLap.Touched:Connect(function(hit)
    if hit.Parent == game.Workspace.myCar then
        endTimeEvent:FireServer()
    end
end)

TimeServerScript - Server Script (ServerScriptService)

This script tracks lap times and fastest times on the server. It uses tick() to measure how long each lap takes and updates the leaderboard.

local repStore = game:GetService("ReplicatedStorage")
local startTimeEvent = repStore:WaitForChild("StartTimeEvent")
local endTimeEvent = repStore:WaitForChild("EndTimeEvent")
local startingTime = 0
local currentLapTime = 0
local db = true
function GetStartingTime()
    startingTime = ()
end
startTimeEvent.:Connect(GetStartingTime)
function GetFinishingTime(localPlayer)
    if startingTime == 0 then return end
    currentLapTime = tick() -
    startingTime = 0
    local plr = game.Players:FindFirstChild(localPlayer.Name)
    local plrStats = plr:WaitForChild("leaderstats")
    local lapTime = plrStats:FindFirstChild("Lap Time")
    if db then
        db = false
        lapTime.Value = currentLapTime
        db = true
    end
    local fastestTime = plrStats:FindFirstChild("Fastest Time")
    if currentLapTime fastestTime.Value then
        fastestTime.Value = currentLapTime
    end
end
endTimeEvent.OnServerEvent:Connect(GetFinishingTime)