Earlier today, I used a guide to make a simple datastore, storing the value of cash. Not only does the code not give any sort of error message after not saving any of the data, after the SetAsync, attempting to print the data variable doesn't work altogether. Is there anyway I can fix this?
(loading code, works fine, just in case though)
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.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
print(data)
if success then
Cash.Value = data
-- Set our data to the player's values
end
end)
(Saving Code(Where the problem likely is))
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = player.leaderstats.Cash.Value
print(data)
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
print(data)
if success then
print("Data successfully saved!")
else
print("There was an error!")
warn(errormessage)
end
end)
Thanks in advance!

2 comments
What does it output?
All it outputs are the several print(data)'s that I put around the code for debug purposes, but no specific error messages. Also, It doesn't print out the one after the SetAsync.