StatsBoard Script
Choose your lesson version below!
Your Custom Settings
Server Script (ServerScriptService) - Basic
This script creates a leaderboard showing each player's lap count. The leaderboard appears automatically in the top-right corner of the screen.
game.Players.:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local leaderstats = .new("Folder", player)
leaderstats.Name = ""
local plrLaps = Instance.new("NumberValue", leaderstats)
plrLaps.Name = "Laps"
plrLaps.Value = 0
end)
end)
Server Script (ServerScriptService) - With Timing
Updated StatsBoard that adds Lap Time and Fastest Time to the leaderboard. Fastest Time starts at math.huge (infinity) so any completed lap will be faster.
game.Players.:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local leaderstats = .new("Folder", player)
leaderstats.Name = "leaderstats"
local plrLaps = Instance.new("NumberValue", leaderstats)
plrLaps.Name = "Laps"
plrLaps.Value = 0
-- NEW: Add these lines for timing
local lapTime = Instance.new("NumberValue", leaderstats)
lapTime.Name = "Lap Time"
lapTime.Value = 0
local fastestLap = Instance.new("NumberValue", leaderstats)
fastestLap.Name = "Fastest Time"
fastestLap.Value =
end)
end)
Server Script (ServerScriptService) - With DataStore
Final version! Saves player data (Laps and Fastest Time) using Roblox DataStoreService so progress persists between sessions. You must publish the game and enable API Services in Game Settings for this to work.
local dss = game:GetService("")
local plrData = dss:("Racing_v0.0.2")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local plrLaps = Instance.new("NumberValue", leaderstats)
plrLaps.Name = "Laps"
plrLaps.Value = 0
local lapTime = Instance.new("NumberValue", leaderstats)
lapTime.Name = "Lap Time"
lapTime.Value = 0
local fastestLap = Instance.new("NumberValue", leaderstats)
fastestLap.Name = "Fastest Time"
fastestLap.Value = math.huge
-- LOAD SAVED DATA
local data = plrData:(player.UserId)
if data ~= nil then
plrLaps.Value = data["Laps"]
fastestLap.Value = data["Fastest Time"]
else
--new player
data = {
["Laps"] = 0,
["Fastest Time"] = 0
}
local success, err = (function()
plrData:SetAsync(player.UserId, data)
end)
end
-- SAVE DATA ON GAME CLOSE
game.OnClose = function()
data = {
["Laps"] = plrLaps.Value,
["Fastest Time"] = fastestLap.Value
}
local success, err = pcall(function()
plrData:SetAsync(player.UserId, data)
end)
end
end)
end)
