Well I just don’t understand where to put anything inside of the empty script! I’ve already made the leaderboard but I don’t know how to make a serverscriptservice script for it since I’m a beginner! I’ve searched on youtube how to do it and nothing really helps me. They all just say use a free model but it has a virus in it. Below are my 2 scripts that I use right now. The local timerGui script which makes the timer show up on the local player’s screen when they pass through the start and stop parts. And the DataSaver script that saves a player’s personal best time! I’ve been looking for help for weeks but nobody will respond. Here’s the game if you want to play it:
local player = Players.LocalPlayer
local currentTime = player:WaitForChild("CurrentTime")
local personalBest = player:WaitForChild("PersonalBest")
local replicatedStorage = game:GetService("ReplicatedStorage")
local function secondsToMinSecMs(seconds)
local minutes = math.floor(seconds / 60)
local remainingSeconds = seconds % 60
local secondsSplit = math.floor(remainingSeconds)
local millisecondsSplit = math.floor((remainingSeconds - secondsSplit) * 100)
return string.format("%02i:%02i.%02i", minutes, secondsSplit, millisecondsSplit)
end
local textLabel = script.Parent
textLabel.Text = "Timer: " .. secondsToMinSecMs(currentTime.Value) .. "\nPersonal Best: " .. secondsToMinSecMs(personalBest.Value)
while true do
textLabel.Text = "Timer: " .. secondsToMinSecMs(currentTime.Value) .. "\nPersonal Best: " .. secondsToMinSecMs(personalBest.Value)
task.wait()
end
**Here is my serverscriptservice DataSaverScript:**
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("PersonalBest")
local replicatedStorage = game:GetService("ReplicatedStorage")
local bestTime = replicatedStorage:WaitForChild("BestTime")
local function playerAdded(plr)
local personalBest = Instance.new("NumberValue")
personalBest.Name = "PersonalBest"
personalBest.Value = dataStore:GetAsync("Best_" .. plr.UserId) or math.huge
personalBest.Parent = plr
local currentTime = Instance.new("NumberValue")
currentTime.Name = "CurrentTime"
currentTime.Value = 0
currentTime.Parent = plr
local startTime = Instance.new("NumberValue")
startTime.Name = "StartTime"
startTime.Value = 0
startTime.Parent = plr
local timerStopped = Instance.new("BoolValue")
timerStopped.Name = "TimerStopped"
timerStopped.Value = true
timerStopped.Parent = plr
personalBest:GetPropertyChangedSignal("Value"):Connect(function()
personalBest.Value = math.clamp(personalBest.Value, 1/math.huge, math.huge)
end)
while true do
if timerStopped.Value == false then
currentTime.Value = tick() - startTime.Value
end
task.wait()
end
end
for _, plr in ipairs(players:GetPlayers()) do
task.spawn(playerAdded, plr)
end
players.PlayerAdded:Connect(playerAdded)
players.PlayerRemoving:Connect(function(plr)
dataStore:SetAsync("Best_" .. plr.UserId, plr.PersonalBest.Value)
end)
game:BindToClose(function()
for _, plr in ipairs(players:GetPlayers()) do
dataStore:SetAsync("Best_" .. plr.UserId, plr.PersonalBest.Value)
end
end)
local startTimer = workspace.StartTimer
local endTimer = workspace.EndTimer
startTimer.Touched:Connect(function(part)
local char = part.Parent
local hum = char:FindFirstChildOfClass("Humanoid")
local plr = players:GetPlayerFromCharacter(char)
if char and plr and hum.Health > 0 and plr.TimerStopped.Value == true then
plr.CurrentTime.Value = 0
plr.StartTime.Value = tick()
plr.TimerStopped.Value = false
end
end)
endTimer.Touched:Connect(function(part)
local char = part.Parent
local hum = char:FindFirstChildOfClass("Humanoid")
local plr = players:GetPlayerFromCharacter(char)
if char and plr and hum.Health > 0 then
plr.TimerStopped.Value = true
if plr.CurrentTime.Value < plr.PersonalBest.Value then
plr.PersonalBest.Value = plr.CurrentTime.Value
end
end
end)