I know someone else has asked this but it hasn't been answered and I'm really stuck and worried I won't be able to find it again. So sometimes my data stores work and sometimes they don't. It's weird. Here's the important code and I'm not getting any errors or errormessage
game.Players.PlayerRemoving:Connect(function(player)
local Id = "player_"..player.UserId
local Data = player.leaderstats.Cash.Value
local success, errormessage = pcall(function()
DataStore1:SetAsync(Id, Data)
print("DataSaved")
end)
if success then
print("DataSaved")
elseif errormessage then
print("There was a error")
warn(errormessage)
end
end)

3 comments
Sorry. I mix things up easily.. I dont know what is wrong with your code then.
nah it's fine
if you are testing the script in studio, try to test your game in the roblox's website instead