task.wait() did not work and as for WaitForChild(), this was my bet but I noticed that it would make a “lag spike” when used. I am not sure if this is due to the function yielding or it working properly but to not waste more time it will use it.
Two things to point out tough, I’m using a mobile device to test; it is a bit laggy and the number of loaded limbs at fire varies each death.
The following is probably the most favorable way of achieving this, as it is entirely event driven (no polling/yielding).
local Game = game
local Players = Game:GetService("Players")
local function OnPlayerAdded(Player)
local function OnCharacterAdded(Character)
local function OnCharacterChildAdded(Child)
if Child.Name ~= "Head" then return end
print(Child.Name.. " found!")
end
Character.ChildAdded:Connect(OnCharacterChildAdded)
local Head = Character:FindFirstChild("Head")
if Head then OnCharacterChildAdded(Head) end
end
Player.CharacterAdded:Connect(OnCharacterAdded)
end
Players.PlayerAdded:Connect(OnPlayerAdded)