Timed Leaderboard
ServerScriptService (Seconds)
local function onPlayerJoin(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local time_ = Instance.new("IntValue")
time_.Name = "Time"
time_.Value = 0
time_.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
local function addTime(player)
while true do
wait(1)
player.leaderstats.Time.Value = player.leaderstats.Time.Value + 1
end
end
game.Players.PlayerAdded:Connect(addTime)
ServerScriptService (Seconds and Minutes)
local function onPlayerJoin(player)
local leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local seconds = Instance.new('IntValue')
seconds.Name = 'Seconds'
seconds.Value = 0
seconds.Parent = leaderstats
local minutes = Instance.new('IntValue')
minutes.Name = 'Minutes'
minutes.Value = 0
minutes.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
local function addTime(player)
while true do
wait(1)
player.leaderstats.Seconds.Value = player.leaderstats.Seconds.Value + 1
if player.leaderstats.Seconds.Value == 60 then
player.leaderstats.Seconds.Value = 0
player.leaderstats.Minutes.Value = player.leaderstats.Minutes.Value + 1
end
end
end
game.Players.PlayerAdded:Connect(addTime)
ServerScriptService (Minutes)
local function onPlayerJoin(player)
local leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local seconds = Instance.new('IntValue')
seconds.Name = 'Seconds'
seconds.Value = 0
seconds.Parent = player
local minutes = Instance.new('IntValue')
minutes.Name = 'Minutes'
minutes.Value = 0
minutes.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
local function addTime(player)
while true do
wait(1)
player.Seconds.Value = player.Seconds.Value + 1
if player.Seconds.Value == 60 then
player.Seconds.Value = 0
player.leaderstats.Minutes.Value = player.leaderstats.Minutes.Value + 1
end
end
end
game.Players.PlayerAdded:Connect(addTime)
DataStore Version
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local function onPlayerJoin(player) -- Runs when players join
local leaderstats = Instance.new("Folder") --Sets up leaderstats folder
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Time = Instance.new("IntValue") --Sets up value for leaderstats
Time.Name = "Time"
Time.Parent = leaderstats
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
-- Data exists for this player
Time.Value = data
else
-- Data store is working, but no current data for this player
Time.Value = 0
end
end
local function onPlayerExit(player) --Runs when players exit
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.leaderstats.Time.Value) --Saves player data
end)
if not success then
warn('Could not save data!')
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
local function onPlayerJoin(player)
while true do
wait(1)
player.leaderstats.Time.Value = player.leaderstats.Time.Value + 1
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)