Battle_NPC = script.Parent; Respawned_Battle_NPC = Battle_NPC:Clone();
while true do wait(1); Battle_NPC_Humanoid = Battle_NPC:FindFirstChild("Humanoid"); if Battle_NPC_Humanoid ~= nil then Joints = { Battle_NPC_RightArm = Battle_NPC:FindFirstChild("Right Arm"); Battle_NPC_LeftArm = Battle_NPC:FindFirstChild("Left Arm"); Battle_NPC_RightLeg = Battle_NPC:FindFirstChild("Right Leg"); Battle_NPC_LeftLeg = Battle_NPC:FindFirstChild("Left Leg"); } local Continue = true; for i, v in pairs(Joints) do if v == nil then Continue = false; end end end end
I know, there is a more simple way to do this, but I want to see if this is possible. I'm trying to get the things in the Table and Destroy them with the :Destroy method. My friend gave me the in pairs loop and I don't know what to do next.
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
I'm not really sure what you're asking for here.
The generic for loop uses an iterator function to pass over all members of a Table. pairs
and ipairs
are the stock iterator functions. pairs
goes over every key-value pair once, but in an indeterminate order. ipairs
only works with integer keys, and will go from 1
to the highest consecutive numbered member.
Examples:
local tab = { "stringMember", 123, --number member "anotherString", NamedMember = "Non-integer!", "anotherStringAgain!", --default again. [5] = 125, [7] = 125, } for i, v in ipairs(tab) do print(i .. " :: " .. v) end print("") for i, v in pairs(tab) do print(i .. " :: " .. v) end
And the output:
1 :: stringMember
2 :: 123
3 :: anotherString
4 :: anotherStringAgain!
5 :: 125
1 :: stringMember
2 :: 123
3 :: anotherString
4 :: anotherStringAgain!
5 :: 125
NamedMember :: Non-integer!
7 :: 125
Note that the NamedMember
was not printed in the position it was declared in in the table. Also note that the value at index 7
was not reached by the ipairs
loop, even though it is an integer: there was no value at 6
so ipairs
stopped!