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

[Data store] Why does this sync so slow?

I made a datastored banlist, but it takes like 30 seconds before it takes effect.

CheckBan = function(plr)
	local PlayerKey = "BannedUser_"..plr.userId
	local DSB = game:GetService("DataStoreService"):GetDataStore(Gravity_V4._DATASTORESync.BanlistLink)
	if DSB:GetAsync(PlayerKey) then
		DSB:UpdateAsync(PlayerKey, function(oldValue)
			local newValue = oldValue or 1
			newValue=newValue+1
			return newValue
		end)
		Gravity_V4._Connections.Broadcast(5,0,'Kicked: '..plr.Name..' for datastored ban!','Really red',nil)
		Gravity_V4._Connections.Kick(plr)
	end
	end


local DSB = game:GetService("DataStoreService"):GetDataStore(Gravity_V4._DATASTORESync.BanlistLink)
local PlayerKey = "BannedUser_"..plr.userId


if DSB:GetAsync(PlayerKey) then
	Gravity_V4._Connections.CheckBan(v)
else
	DSB:SetAsync(PlayerKey,1)  -- This is SLOW, but why?
	Gravity_V4._Connections.CheckBan(v)
end

8 comments

0

Most likely the DataStore service is being overloaded.

0

The problem is, the only time the banlist run's is when a player enters, And the CheckBan function runs FAST.. But for some reason the setasync is slow.

0

Any idea's?

0

I'm not entirely sure if this will work, but try and implement :WaitForDataReady(). Wiki's description for this isn't too specific on its use, but I believe you can pre-load data from a given player with this player method.

0

But isnt :WaitForDataReady() for Data persistence not Data store?

1

...Thanks for specifying that. I'm not too experienced with Data Persistence, as you can see. My apologies.

0

No worrys. I will up rep your comment for trying to help. Hey, you learn something everyday! :P

0

Plus you have helped me in the past, so yea.. :)

1 answer

✓ Accepted answer

Your problem is that you're attempting to read from the DataStore immediately after writing to it. DataStores caches on the current server once about every thirty seconds (IIRC), so you have a large delay before the ban works.

To get around this, separate the DataStore code from the banning code. Maintain your own cached banned players (as a Table) , and check that list before checking the DataStore itself. If the player isn't on the list, check the DataStore, and enter the player into the list as either Allowed or Banned, running the banned function for the Player if they are banned.

Now, this has the potential to use up your allocated bandwidth if you spam the ban command too much, so I suggest only pushing your banlist to the DataStore every ten or so seconds, and have the ban command itself only add or remove people from the Table.

1 comment

0

Thank you so much! I will have to figure out the banned table but it explains why the Datastore is running so slow!

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