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
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.