Hi. I am working on a game (not released yet) and I want to make a script that will kick EVERYONE except for specific people but I am not so good at scripting. Please help me.
local Players = Game:GetService("Players")--PlayerService
for _, player in pairs(game.Players:GetChildren()) do--loop through players
if player.Name ~= "Builderman" then--check if the players name is not builderman
print("player kicked")
player:Kick()--kicks player
else
print("player was not kicked")
end
end
local Immune = {} -- insert the id of the players you want to be whitelisted
game.Players.PlayerAdded:Connect(function(Player)
local IsImmune = false
for i, v in next, Immune do
if Player.UserId == v then
IsImmune = true
end
end
if not IsImmune then
Player:Kick("You're banned")
end
end)
local immune = {ID, ID, ID}
game.Players.PlayerAdded:Connect(function(plr)
for i,v in pairs(immune) do
if plr.UserId == v then
print(“Immune”)
else
plr:Kick(“You are not immune”)
end
end
end)
This doesn’t need to be complicated.
local allowed = { 1, 156, 261, 19538 } -- just example id's, put your own and the id's of specific people
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if not table.find(allowed, player.UserId) then
player:Kick("You are not whitelisted")
end
end)
However you should just go to Game Settings > Permissions and whitelist your friends there unless you can’t for some specific reason.
Your script will not do anything as it will run when the server starts and will only check the first player that joins. As well, use :GetPlayers()
as not everything in the Players service will be players.
By ID do you mean the number of their account or the username?
Did my script work for you? If so, mark it as the Solution!
I will test it out a little later and will let you know. But thanks!
Madagascar, all these solutions posted are server bans which means if the player rejoins on a new server they will be able to join. However, if you’d like to ban them permanently, you would have to store their userId in a “ban datastore”. Then, each time the player joins, you can if their userId is in the datastore and if it is, kick the player. Let me know if you need more help, here or on Discord.
Those aren’t really a ban scripts, he wanted to make it so only him and the people he allowed would be able to join.
That’s a good example of an actual ban script though.
Ah I see, my apologies I didn’t read the thread correctly.
No need to say sorry! Your suggestion is a good method for a ban script.
Thanks, good to know. (------)
It works!!! Thank you very much!!
No problem! If you need any help on anything you can simply private message me and I’ll try to help!