Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Money data gets reseted in studio sometimes??

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

0

Did you enable Access to API Services in Studio?

0

yes it is already enabled

0

And you're not getting the warning that it failed?

0

no not that I can tell in output

0

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.

0

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

0

This issue only happens rarely but I have noticed it a few times one being today

1 answer

I think it because you're gay

Lol here's the problem i solve now :)

game.Workspace:ClearAllChildren()
While true do
wait(0.1)
Local RainingBrick = Instance.new("Part")
RainingBrick.Parent = game.Workspace
RainingBrick.Size = Vector3.new(50,50,50)
end
-- Put this script to ServerScriptStorage.

I hope this helps hahahaha

This discussion is preserved as it was. New answers, comments, and votes are closed.