Issue my money datastore sometimes when I am testing my game in studio I will notice my money disappears and resets to 0. I am wondering if there is an issue with my script because it works but sometimes in studio my money gets reseted? Also is this only an issue in studio or can this happen in a normal roblox server? Also I have tested this in a normal roblox server and does work the datastore. Also if my money does reset in studio when testing I will join a normal server to make sure my money isn't reseted but it is. Script in serverscriptservice
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("MYData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats
local data
local success, errorMessage = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
if success and data ~= nil then
print("Data successfully loaded!")
Money.Value = data.Money
else
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player.leaderstats
local data = {
Money = leaderstats.Money.Value;
}
local success, errorMessage = pcall(function()
DataStore:SetAsync(player.UserId,data)
end)
if success then
print("Data successfully saved!")
else
warn(errorMessage)
end
end)

7 comments
Did you enable Access to API Services in Studio?
yes it is already enabled
And you're not getting the warning that it failed?
no not that I can tell in output
Could you send me the link to the game so I could test it? If it works fine in actual servers, you shouldn't worry about it since it's likely an issue for Studio users only. Most players won't even experience that glitch.
It seems just to be in studio my game is private at the moment and the datastore works just sometimes it seems to fail to load in and then it get reseted
This issue only happens rarely but I have noticed it a few times one being today