Alright so, I want to make a leaderboard which passes by minutes & want that time to be saved once the player leaves the game. I’ve checked youtube & looked up on the roblox toolbox but nothing actually helped.
If anyone can help me figure out how I can have a leaderboard and add time by minute and keep that time saved in a datastore could be amazing!
Apologies if I’m in the wrong category on posting this. I need help on how to figure this out, new to scripting
Your objective is very simple, in order to actually save it, you’ll need a datastore. Try to set one up based on the tutorial. If it doesn’t work, reply and provide your code.
Like WooleyWool said you need to strore it in data stores
I made an example!
Here it is
The code waits 60 seconds to increase the counter
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("TotalTime")
local Players = game:GetService("Players")
local sessionData = {}
local AlwaysTrue = true
-- Function to save player's data
local function savePlayerData(playerUserId, plr)
playerData:SetAsync(playerUserId, plr.leaderstats.Time.Value)
print("Saved!")
end
-- Function to save player data on exit
local function saveOnExit(player)
local playerUserId = "Player_" .. player.UserId
savePlayerData(playerUserId, player)
end
local function onPlayerAdded(plr)
local playerUserId = "Player_" .. plr.UserId
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = 'leaderstats'
local timee = Instance.new("IntValue")
timee.Parent = leaderstats
timee.Name = 'Time'
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("TotalTime")
local playerUserId = "Player_" .. plr.UserId
local sessionData = {}
local data = playerData:GetAsync(playerUserId)
timee.Value = data
repeat
wait(60)
local newTime = timee.Value + 1
timee.Value = newTime
until AlwaysTrue == false
end
Players.PlayerRemoving:Connect(saveOnExit)
Players.PlayerAdded:Connect(onPlayerAdded)