Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make it so certain users are kicked when they join?

Asked by 5 years ago

I want to ban a few users from my game but I'm not sure how to do it.. this is what I tried

game.Players.PlayerAdded:Connect(function(plr)
if plr.userid = 1 or plr.userid = 2 or plr.userid = 3 then
plr:Kick("banned")
end
end

Can someone help?

0
`==` is for equality, `=` is for defining. Also I suggest using a dictionary with string indexes so you can cut down on the amount of `or`'s EpicMetatableMoment 1444 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

Try this:

game.Players.PlayerAdded:Connect(function(plr)
    if plr.UserId == 1 or plr.UserId == 2 or plr.UserId == 3 then
        plr:Kick("You are banned!")
    end
end

You did not use the right property or equals operator.

0
thanks Everyoneee 0 — 5y
0
As he didn't explain your error, you should use the double equal operator when comparing two statements/conditions and the single operator when setting or changing a value (of a variable). turtle2004 167 — 5y
Ad
Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

This is what you’re looking for

local Players = game:GetService(“Players”):GetPlayers()
local Banned = {1,2,3}
game.Players.PlayerAdded:Connect(function(Player)
   for _BannedPlayer in ipairs(Banned) do
      if Player ~= BannedPlayer then
         return true
      end
      Player:Kick(“You’ve been Banned”)
   end
end

First, your issue was that you were using the wrong type of operator = means assign, and == means is equal to, you wanted to use is equal to, for this script it will check if it is not equal to or ~= return true will stop the rest of the Script running if the Player isn’t Banned, if they are, kick em’

0
If this helps, or is more effective, don’t forget to press accep answer! Ziffixture 6913 — 5y
Log in to vote
0
Answered by 5 years ago

put in a LocalScript inside StarterGui.

banned = {
    "plsdontbanme",
    "someoneyoudontlike",
}

for i,v in pairs(banned) do
    if game:GetService("Players").LocalPlayer.Name == v then
        game:GetService("Players").LocalPlayer:Kick("I DONT LIKE YOU")
    end
end

Answer this question