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.Value = 0
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.Player.PlayersRemoving: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)

5 comments

0

It probably works, you just haven't added cash onto yourself.

0

i have another script for that

0

Does it work?

0

no when i played the game, the cash didn't save

0

yea the other script works