Why isn't my ban script working?

I am trying to make a ban list script but for some reason it isn’t working.

2 Likes

You’ll Need to use data stores for this to work cross-server and after restarts. I’m on my phone now but I could make you some code soon.

1 Like

I’m quite new to scripting as I typically build so I’m not sure how to implement those.

1 Like

Because you are destroying a player before even kicking it which will still make them stay in game but can’t do anything so just remove that player:Destroy() and you are fine oh and also if you want it to kick everyone except you that joins the game then do this script:

--Basically the same script
local BanMessage = 'Sorry only GreekRootWord has access until the game is done!'

game.Players.PlayerAdded:Connect(function(player)
          for i,v in pairs(game.Players:GetPlayers()) do --Except you will change it to i,v in pairs() which basically gets all the players and "i" stands for index and "v" stands for value
                 if not v.Name == "GreekRootWord" then --If the player's username isn't the same as your username then
                            v:Kick(BanMessage) --kick the player
                  end
           end
end)
1 Like

Fair enough. I’ll try to make and explain some code for you soon, but in the meantime you could google the search term ‘Roblox datastore’

Hello, you don’t need for _ do loop for this function.
Instead, you can use table.find

Here’s your code:

local BannedPlayers = {'Sekreth_amon', 'InfiniteWaterBucket'}

local BanMessage = 'Sorry only GreekRootWord has access until the game is done!'

game:GetService("Players").PlayerAdded:Connect(function(player)
   if table.find(BannedPlayers, player.Name) then
      player:Kick(BanMessage)
   end
end)

Also, if you are willing to whitelist player named ‘GreekRootWord’, use this code instead:
Or, you might want to make game private, so no one else besides you can join the game.

local WhitelistedPlayers = {'GreekRootWord'}

local BanMessage = 'Sorry only GreekRootWord has access until the game is done!'

game:GetService("Players").PlayerAdded:Connect(function(player)
   if not table.find(WhitelistedPlayers, player.Name) then
      player:Kick(BanMessage)
   end
end)
3 Likes

Thank you, it finally worked. I will put you in the credits.

1 Like