Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

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

3 answers

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.

2 comments

0

thanks

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).

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’

1 comment

0

If this helps, or is more effective, don’t forget to press accep answer!

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

This discussion is preserved as it was. New answers, comments, and votes are closed.