So I have this group kicker, that if you are in this group, it kicks you, but I want it to be so a certain player, that if there in the a group, it DOESN’T kick them. Here is the group kicker script with my attempt at making this.
local Groups = {2565865,3124648,2867104,2593876,2732062,3060600,3109968,2651059,3047330,2633144,3454957};
local function isInBanned(plr)
for i, v in pairs(Groups) do
if plr:IsInGroup(v) then
return true;
end
end
return;
end
game:GetService("Players").PlayerAdded:connect(function(plr)
if isInBanned(plr) then
plr:Kick("noob leave that trash group")
else
if plr.Name == "DeisredWorl" or plr.Name == "JackMercando" then
end
end
end)
The trick here is that in your if statement, if it evaluates to true, the player should be kicked. Therefore, you use this to your advantage by adding the player name checks (which should be UserId checks) to the if statement.
If the user’s name matches the users you don’t want kicked, then the if condition evaluates to false and does not kick the user. Here is an updated version of your if statement:
if isInBanned(plr) and not (plr.Name == "DeisredWorl" or plr.Name == "JackMercando") then
The elseif bit won’t run if the first part evaluates to true and you won’t be needing it, so get rid of it.
You can make a new table for whitelisted players and edit the if statement in the isbanned function to call table.find with the player’s name to look in the whitelisted player table like so:
local Groups = {2565865,3124648,2867104,2593876,2732062,3060600,3109968,2651059,3047330,2633144,3454957};
local WhitelistedPlayers = {"username1", "username2"}
local function isInBanned(plr)
for i,v in pairs(Groups) do
if plr:IsInGroup(v) and not table.find(WhitelistedPlayers, plr.Name) then
return true
end
end
return nil
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
if isInBanned(plr) then -- alternatively you can check if the player is whitelisted here and not in isbanned function
plr:Kick("noob leave that trash group")
end
end)
And for future reference, please use indentation; it makes your script a lot easier to read.
AllowedUserIDs = { game.Players:GetUserIdFromNameAsync("DeisredWorl"),
game.Players:GetUserIdFromNameAsync("JackMercando")
}
game:GetService("Players").PlayerAdded:connect(function(plr)
if isInBanned(plr) and not AllowedUserIDs[plr.UserId] then
plr:Kick("noob leave that trash group")
end
end)
Here’s some untested code
and here’s that same code but using Usernames instead
(Though I recommend using UserID)
AllowedUsernames = {'dispeller','Builderman','John Doe'}
game:GetService("Players").PlayerAdded:connect(function(plr)
if isInBanned(plr) and not AllowedUsernames[plr.Name] then
plr:Kick("noob leave that trash group")
end
end)
And finally, here’s a method of doing it that both looks nice and is easy to use, though it does involve a tiny bit more complexity, but not by much
AllowedUsers = {"DeisredWorl","JackMercando","John Doe",193694100,156}
-- Add UserIDs of all UserNames on list to list
for i,v in pairs(AllowedUsers) do
if type(v)=='String' then
table.insert(AllowedUsers,game.Players:GetUserIdFromNameAsync(v))
end
end
game:GetService("Players").PlayerAdded:connect(function(plr)
if isInBanned(plr) and not AllowedUsers[plr.UserId] then
plr:Kick("noob leave that trash group")
end
end)
again, all of this code is untested and it is 11:32PM for me right now
(also, u should probs include the isInBanned function in the code aswell)
I’m going to sleep, good night
As @PostApproval mentioned, this untested code won’t work. I wrote this late at night. Good to know GetUserIdFromNameAsync is a web call though
All your code samples fundamentally will not work (or rather they will but they won’t act as expected) because you are attempting to perform table lookups on nil indices. You need to use a dictionary to be able to do lookups in this manner, not an array.
In general, you shouldn’t repeatedly call GetUserIdFromNameAsync because it’s still internally a web call and subject to invisible limitations (implied that you shouldn’t be calling it so many times a minute).