local datastore=dss:GetDataStore('DataStore')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats=Instance.new('Folder')
leaderstats.Parent=player
leaderstats.Name='leaderstats'
local coins=Instance.new('IntValue')
coins.Parent=leaderstats
coins.Name='coins'
local success,data =pcall(function()
return datastore:GetAsync(player.UserId)
end)
if success and data then
coins.Value=data
else
warn('cant find coins profile for'.. player.Name)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local coins=player:FindFirstChild('leaderstats'):FindFirstChild('coins')
local success,err=pcall(function()
datastore:SetAsync(player.UserId,coins.Value)
end)
if not success then
warn('cant save coins profile')
end
end)```