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

How would I exclude a child from GetChildren()/incorporate an if-statement into a for loop?

Asked by 8 years ago
Edited 8 years ago

I've created an admin-only surface GUI, and one of the buttons kills all players. The script is as follows:

script.Parent.MouseButton1Click:connect(function()
    local P = game.Players:GetChildren()

    for i = 1, #P do
        wait()
        P[i].Character.Head:Remove()
    end 
end)

I was wondering if it would be possible to check if the players name is X (X being a predetermined name of an admin (or admins?)) and if so, then don't kill that player, else, if it isn't the name of an admin, kill the player. Would you have any idea as to how I would incorporate that into this for loop? Thanks for any and all help! Cheers!

2 answers

Log in to vote
2
Answered by 8 years ago

You would simply make sure that it isn't the admin that the for loop is about to kill, before proceeding with the actual killing

script.Parent.MouseButton1Click:connect(function()
    local P = game.Players:GetChildren()

    for i = 1, #P do
        wait()
    if not (Character.Name == ADMIM_NAME_HERE) then --IF this is NOT the admin, then kill the specified character.
            P[i].Character.Head:Remove()
    end
    end 
end)

0
Thank you very much! Brinceous 85 — 8y
0
Your welcome! Glad I could help! dragonkeeper467 453 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Try this

script.Parent.MouseButton1Click:connect(function()
    local P = game.Players.LocalPlayer

    if P.Character.Name == 'adminname' then
        whatever you want to happen
    else
        P.Character.Humanoid.Health = 0
end
end)
0
or use a not condition. OniiCh_n 410 — 8y
0
This will work, but you need to provide more of an explanation dragonkeeper467 453 — 8y
0
so why i no get rep ;-; UsernameEqualsTaken 30 — 8y

Answer this question