I am working on a ban list that is supposed to add banned players to a datastore that all servers can access. However, it is only kicking the players once and not banning them. Also, I made a ban list GUI and their name is not being entered there for the admins to see just in case they want to unban anyone. I really need help.
Script:
dataStoreService = game:GetService("DataStoreService"):GetOrderedDataStore("BanList")
banPlayer = game.ReplicatedStorage.BanPlayer
kickPlayer = game.ReplicatedStorage.KickPlayer
unbanPlayer = game.ReplicatedStorage.UnbanPlayer
listChanged = game.ReplicatedStorage.ListChanged
local function findNextAvailableKey()
local key = 1
while true do
local isAvailable
local success, notSuccess = pcall(function()
isAvailable = dataStoreService:GetAsync(key)
end)
if notSuccess then
warn(notSuccess)
end
key = key + 1
if isAvailable == nil then return key end
end
end
local function sendList()
local list = {}
local key = 1
while true do
local player
local success, notSuccess = pcall(function()
player = dataStoreService:GetAsync(key)
end)
if notSuccess then
warn(notSuccess)
end
key = key + 1
if player ~= nil then table.insert(list, game.Players:GetNameFromUserIdAsync(player)) else break end
end
listChanged:FireAllClients(list)
end
local function addToDataStore(player, plr)
local success, notSuccess = pcall(function()
dataStoreService:SetAsync(findNextAvailableKey(), plr.UserId)
end)
if notSuccess then
warn(notSuccess)
end
sendList()
return "Added"
end
local function checkIfInList(player)
local key = 1
while true do
local isThere
local success, notSuccess = pcall(function()
isThere = dataStoreService:GetAsync(key)
end)
if notSuccess then
warn(notSuccess)
end
key = key + 1
if isThere == player.UserId then return true end
if isThere == nil then return false end
end
end
local function accumulate()
local list = {}
local nilCount = 0
local key = 1
while true do
local value
local success, notSuccess = pcall(function()
value = dataStoreService:GetAsync(key)
end)
if notSuccess then
warn(notSuccess)
end
if value == nil then
nilCount = nilCount + 1
else
table.insert(list, value)
end
if nilCount >= 2 then break end
end
return list
end
local function reorderData()
local data = accumulate()
local key = 1
for _, value in pairs(data) do
local success, notSuccess = pcall(function()
dataStoreService:SetAsync(key, value)
end)
if notSuccess then
warn(notSuccess)
end
key = key + 1
end
end
local function removePlayer(player, ID)
local key = 1
while true do
local success, notSuccess = pcall(function()
local player = dataStoreService:GetAsync(key)
end)
if notSuccess then
warn(notSuccess)
end
if player == ID then
local success, notSuccess = pcall(function()
dataStoreService:RemoveAsync(key)
end)
if notSuccess then
warn(notSuccess)
end
end
key = key + 1
end
reorderData()
sendList()
return 0
end
game.Players.PlayerAdded:Connect(function(player)
if checkIfInList(player) then
kickPlayer:Fire(player)
end
sendList()
end)
banPlayer.OnServerInvoke = addToDataStore
unbanPlayer.OnServerInvoke = removePlayer

2 comments
i dont know but please upvote me
I think there is actually one from the dev forums, you should search it up. It is used in games like lumber tycoon