How can i stop X is not a valid member of model Y after a part gets destroyed

I’m having a simple (i tihnk) but annoying problem, this is a part of code of a tool:

if Hit.Parent:FindFirstChildWhichIsA("Humanoid").Health <= 0 and Hit.Parent.HumanoidRootPart ~= nil then
		Hit.Parent.HumanoidRootPart:Destroy()
	end

Well, so what im passing through is that after the HumanoidRootPart gets destroyed, it warns in the output:

"HumanoidRootPart is not a valid member of model “Workspace.Rig”

You can use Instance:FindFirstChild(name)

In this case, you can do:

if Hit.Parent:FindFirstChildWhichIsA("Humanoid").Health <= 0 and Hit.Parent:FindFirstChild("HumanoidRootPart") then
	Hit.Parent.HumanoidRootPart:Destroy()
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.