Idk why but it's not saving
local dataStore = game:GetService("DataStoreService")
dataStore:GetDataStore("Cash")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local data
local success,err pcall(function()
data = dataStore:GetAsync(plr.UserId)
end)
if success then
cash.Value = data
elseif err then
warn(err)
print("when plr joining saving data didnt work")
end
game.Players.PlayerRemoving:Connect(function(plr)
local success,err pcall(function()
dataStore:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
end)
if success then
print("Worked saving")
elseif err then
warn(err)
print("something went wrong saving data")
end
end)
end)

2 comments
Fix the code block
you had a space before the ~~~ so it will not use code block. Please preview the question before posting it