The title pretty much some it up, my leaderstats cash script, isn’t saving to the Data Store. Please tell me why. Thanks Devs.
local DataStoreService = game:GetService("DataStoreService")
local PlayerCash = DataStoreService:GetDataStore("PlayerCash")
function OnPlayerAdded(player)
local stats = Instance.new("Folder", player)
stats.Name = 'leaderstats'
local Cash = Instance.new("NumberValue", stats)
Cash.Name = "Cash"
Cash.Value = 0
local data
local success, err = pcall(function()
data = PlayerCash:GetAsync(player.UserId)
end)
if success then
print("Data loaded!")
else
print("There was an error While Getting Data" ..player.Name)
warn(err)
end
end
function OnPlayerRemoving(player)
local success, err = pcall(function()
PlayerCash:SetAsync(player.UserId, player.leaderstats:FindFirstChild("Cash").Value)
end)
if success then
print("Data Saved!")
else
print("There was an error while saving data of player " .. player.Name)
warn(err)
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)