Error with datastore

Hey all, I’m coding this checkpoint saver, but when the user touches the part, an error comes:


I’ve added a debounce, but it still seems to have the same issue.

for _, Cehckp in pairs(checkpointsTable) do
	Cehckp.Touched:Connect(function(plr)
		if debounce == true then
			DataStore:SetAsync(getUserIdFromUsername(plr.Parent) .."-stage",Cehckp.Name)
			if plr and plr.Parent then
				debounce = false
				print(Cehckp.Name.. " " .. plr.Parent.Name)
				wait(5)
				debounce = true
			end
		end
	end)
end 

Any help is appreciated, thanks!

1 Like

You have asked for data too many time, so roblox said no to your request. Try asking for data less often (like once a minute).

Yes, I know that. The issue is that Roblox is ignoring the debounce which makes it spam.

it seems like the Debounce isn’t working, you should set the Debounce to false right after the Touched Event ends.

No, the issue is definitely not the debounce. Even if you fix the debounce, the problem will still exist, which is that you’re writing to a DataStore every time a part is touched.

There are limitations to DataStores that you need to be mindful of and this code will not respect those limits. What you should be doing is saving data when a player leaves, not when they touch the checkpoint. The checkpoint should only change the stage they’re on but it should not do any saving itself.

3 Likes

As it has been said already, the issue is not that Roblox is ignoring your debounce.
The userid that is in the warning message (73502) leads to this profile Instance - Roblox. They have the name “Instance”, it seems like you aren’t actually checking if what is hit is a player in your code.

Before you call SetAsync check if plr is actually a part of a players character, you can do this with the players service and a bit of code like this:

local player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
if player then
    -- Do datastore and debounce things
end

Datastore has too many limitations. Try using it often and try using the debouce often.

Hey, I changed the system to save it on a StringValue and when on leave it checks that and does the changes. I am getting this error though:
104: Cannot store Instance in data store. Data stores can only accept valid UTF-8 characters.

As far as I am aware, this still saves the same.
Old:


New:

Saving:
image

What is the value of StageNumber when this error occurs? I don’t have enough information to help you. It would also be helpful if you posted your code into the thread as code boxes instead of images so people here who may help you with this problem can actually copy parts of the code to work with.

The StageNumber is “Stage 3” when this happens. It didn’t error with the previous one. I will change them to codeblocks soon.

add debounce after if statement.
Because it sets datastore then check plr.parent
then debounce turn into false.

image

Also you did a mistake in :SetAsync() you put plr.Parent instead of plr.Parent.Name

I fixed everything in this script:

Show
  for _, Cehckp in pairs(checkpointsTable) do
    	Cehckp.Touched:Connect(function(plr)
    		if debounce == true then -- check if db equals true
                debounce = false -- sets db to false then call database function
    			DataStore:SetAsync(getUserIdFromUsername(plr.Parent.Name) .."-stage",Cehckp.Name)
    			if plr and plr.Parent then
    				print(Cehckp.Name.. " " .. plr.Parent.Name)
    				wait(5)
    				debounce = true
    			end
    		end
    	end)
    end
1 Like