Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

[Data store] Why does this sync so slow?

Asked by 9 years ago

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
0
Most likely the DataStore service is being overloaded. Diitto 230 — 9y
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. MessorAdmin 598 — 9y
0
Any idea's? MessorAdmin 598 — 9y
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. Redbullusa 1580 — 9y
View all comments (4 more)
0
But isnt :WaitForDataReady() for Data persistence not Data store? MessorAdmin 598 — 9y
1
...Thanks for specifying that. I'm not too experienced with Data Persistence, as you can see. My apologies. Redbullusa 1580 — 9y
0
No worrys. I will up rep your comment for trying to help. Hey, you learn something everyday! :P MessorAdmin 598 — 9y
0
Plus you have helped me in the past, so yea.. :) MessorAdmin 598 — 9y

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

0
Thank you so much! I will have to figure out the banned table but it explains why the Datastore is running so slow! MessorAdmin 598 — 9y
Ad

Answer this question