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