local DataStoreService= game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local cash = Instance.new("IntValue") cash.Name = "cash"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data=myDataStore:GetAsync(player.UserId.."-cash")
end)
if success then
cash.Value=data
else
print ("There was an error")
warn (errormessage)
end
end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage =pcall (function() myDataStore:SetAsync(player.UserId.."cash",player.leaderstats.cash.Value) end) if success then print ("Player data saved successfully") else print ("There was an error when saving data") warn(errormessage) end end)

2 comments
oof didnt format correctly
i put code blocks at the start and at the end of the code. I don't know why it's like this, it looks terrible.