0

# How Can You Make A Leaderstat Saving System?

I've been trying to study on how this datastore system works, I'm still a bit stuck on this saving script. This is what I got.

local DataStore = game:GetService("DataStoreService")

Cash.Name = "Cash"
Cash.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)

game.Players.PlayerRemoving:connect(function(player)
end)


It would really be helpful if you could help me :D

2
Edited 1 year ago
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("MyDataStore")

Cash.Name = "Cash"

local data

local success, errormessage pcall(function()

data = ds:GetAsync(player.UserId.."-cash")
Cash.Value = data
end)

game.Players.PlayerRemoving:connect(function(player)
local success, errormessage pcall(function()