Ok, make a script that is in the workspace. Next I want you to copy this and put it in.
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local secs = Instance.new("IntValue")
secs.Name = "Time"
secs.Value = 0
secs.Parent = stats
stats.Parent = newPlayer
while true do
wait(1)
secs.Value = secs.Value + 1
end
end
game.Players.ChildAdded:connect(onPlayerEntered)
This is your time counter, this is the little thing that says time in the leaderboard.
Now make a script and put it in ServerScriptService. Okay copy and paste below into it
– Put this in ServerScriptService
– Saving and Loading settings –
local AUTO_SAVE = true – Make true to enable auto saving
local TIME_BETWEEN_SAVES = 60 – In seconds (WARNING): Do not put this lower than 60 seconds
local PRINT_OUTPUT = false – Will print saves and loads in the output
local SAFE_SAVE = false – Upon server shutdown, holds server open to save all data
local players = game:GetService(“Players”)
local dataStoreService = game:GetService(“DataStoreService”)
local leaderboardData = dataStoreService:GetDataStore(“LeaderStats”)
local function Print(message)
if PRINT_OUTPUT then print(message) end
end
local function SaveData(player)
if player.userId < 0 then return end
player:WaitForChild(“leaderstats”)
wait()
local leaderstats = {}
for i, stat in pairs(player.leaderstats:GetChildren()) do
table.insert(leaderstats, {stat.Name, stat.Value})
end
leaderboardData:SetAsync(player.userId, leaderstats)
Print(“Saved “…player.Name…”'s data”)
end
local function LoadData(player)
if player.userId < 0 then return end
player:WaitForChild(“leaderstats”)
wait()
local leaderboardStats = leaderboardData:GetAsync(player.userId)
for i, stat in pairs(leaderboardStats) do
local currentStat = player.leaderstats:FindFirstChild(stat[1])
if not currentStat then return end
currentStat.Value = stat[2]
end
Print(“Loaded “…player.Name…”'s data”)
end
players.PlayerAdded:connect(LoadData)
players.PlayerRemoving:connect(SaveData)
if SAFE_SAVE then
game.OnClose = function()
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
wait(1)
end
end
while AUTO_SAVE do
wait(TIME_BETWEEN_SAVES)
for i, player in pairs(players:GetChildren()) do
SaveData(player)
end
end
Hopefully this helps!