Recently i tried saving the data when the PlayerRemoving event gets triggered but it simply doesn’t work at all, i’ve been trying to fix this for a week now but i can’t find any possible way, the thing is, that it doesn’t save the coins value but neither does it warn: Cannot save data for player, please help.
local CoinsKey = "-Coins"
local CoinsDataStore = game:GetService("DataStoreService"):GetDataStore("CoinsDataStore")
local function SaveCoins(Player)
local tries = 0
local success
repeat
tries = tries + 1
success = pcall(function()
CoinsDataStore:SetAsync(Player.UserId..CoinsKey,Player.PrivateStats.Coins.Value)
end)
until tries == 3 or success
if not success then
warn("Cannot save data for player!")
end
end
game.Players.PlayerRemoving:Connect(SaveCoins)