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

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

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

✓ Accepted answer

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)

2 comments

0

Thank you very much!

0

Your welcome! Glad I could help!

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)

3 comments

0

or use a not condition.

0

This will work, but you need to provide more of an explanation

0

so why i no get rep ;-;

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