local ds = game:GetService("DataStoreService")
local cs = ds:GetDataStore("Cash")
game.Players.PlayerAdded:Connect(function(plr)
local Cash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")
local data
local succ, err = pcall(function()
data = cs:GetAsync(plr.UserId.."_cash", Cash)
if succ then
Cash = data
print("a")
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local data = plr.leaderstats.Cash.Value
local succ, err = pcall(function()
cs:SetAsync(plr.UserId.."_cash", data)
if succ then
print("it worked")
else
warn(err)
end
end)
end)
please help! it says
nil
when i leave which means nothing or there was an error

2 comments
Replace it with this:
Replace it with this: local Players = game:GetService("Players") local DataStoreService = game:GetService("DataStoreService") local Saver = DataStoreService:GetDataStore("SaveLeaderstats")
Players.PlayerAdded:Connect(function(player) local Data = nil local success, errormessag