I want to make a script that kicks everyone in the server except for 3 players: "H3kken", "17alwin17" and "Is3nty".
I tried making it this way:
for i,v in pairs(game.Players:GetChildren(plr)) do if plr.Name == "H3kken" or "17alwin17" or "Is3nty" then print("Left player behind in server") else v:Kick("This server has shut down.") end end
Before you fix your problem you must first know truthy values and falsey values.
Truthy values in Lua are anything that is not false or nil. Strings, numbers and tables are examples of truthy values.
Falsey values are just false or nil.
or
, and
, not
are all logical operators
.
x or y
evaluates to x
if x
is truthy, y
otherwise.
x and y
evaluates to x
if x
is falsey, y
otherwise
not x
evaluates to true
if x
is falsey, false
otherwise.
Now that you know truthy values
and how logical operators
work, let's fix the codes.
:GetChildren()
doesn't take any arguments and you never defined plr
anywhere.
It's possible to place non-Player instances in the Players service (you shouldn't anyways but it's still possible) so you should use :GetPlayers()
.
You can use a dictionary with the names and check if their name is in the dictionary like so
local playersToNotKick = { ["H3kken"] = true, ["17alwin17"] = true, ["ls3nty"] = true } for _, player in pairs(game.Players:GetPlayers())) do -- player is much better than v or plr! if playersToNotKick[player.Name] then print("Left player behind in server") else player:Kick("This server has shut down.") end end