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?
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?
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.
thanks
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’
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.
1 comment
==is for equality,=is for defining. Also I suggest using a dictionary with string indexes so you can cut down on the amount ofor's