I'm trying to make my leaderboard save my data but i don't understand https://developer.roblox.com/articles/Saving-Player-Data so can someone help me or make a script for me? here is my code: local players = game:GetService("Players") local leaderboardData = game:GetService("DataStoreService"):GetDataStore("LeaderStats")
local button = script.Parent game.Players.PlayerAdded:Connect(function(player) local leader = Instance.new("Model", player) leader.Name = "leaderstats" local cash = Instance.new("IntValue", leader) cash.Name = "Cash" local crimelevel = Instance.new("IntValue", leader) crimelevel.Name = "Crime Level" crimelevel.Value = 0 end) the code is located in SeverScriptService.
You can use mine if you want.
local DataStore = game:GetService("DataStoreService"):GetDataStore("Something") -- In Something put a text like 'Coins' 'CoinSave' etc. it is up to you. game.Players.PlayerAdded:Connect(function(player) local key = "Coins_ID:"..player.UserId local folder = Instance.new("Folder",player) folder.Name = "leaderstats" local coins = Instance.new("IntValue",folder) coins.Name = "Coins" coins.Value = 0 local save = DataStore:GetAsync(key) if save then coins.Value = save end repeat DataStore:SetAsync(key,coins.Value) wait(5) until game.Players.PlayerRemoving game.Players.PlayerRemoving:Connect(function() DataStore:SetAsync(key,coins.Value) end) end)
I use this and it will create a leaderboard, and save it every 5 seconds![and when a player is leaving]