← Back to Racing Scripts

Lap Counter Script

Customize your variables, then fill in the blanks!

Your Custom Settings

Must match leaderboard stat
RemoteEvent in ReplicatedStorage
Part in Workspace
Part in Workspace

Server Script (ServerScriptService)

This script counts laps when the LapEvent is fired. It uses a debounce and cooldown to stop laps being counted too fast.

local repStore = game:GetService("ReplicatedStorage")
local lapEvent = repStore:WaitForChild("LapEvent")
local lapReset = game.:WaitForChild("LapStart")
local lapEnd = game.Workspace:WaitForChild("LapEnd")
local debounce =
local lapCooldown = false
lapReset.:Connect(function()
    debounce = true
end)
lapEnd.Touched:Connect(function()
    debounce = false
end)
function incrementLapCount(localPlayer)
    if not debounce then return end
    local plr = game.Players:FindFirstChild(localPlayer.Name)
    if lapCooldown then return end
    lapCooldown = true
    local plrStats = plr:WaitForChild("")
    local plrLap = plrStats.Laps
    plrLap.Value 1
    task.wait(1)
    lapCooldown = false
end
lapEvent.OnServerEvent:Connect(incrementLapCount)