Killpart not working

Hey guys, i just started scripting and i have a doubt on why my killpart script isnt working
local part = script.Parent part.Touched:Connect(function(touch) if touch.Parent:IsA("Humanoid") then touch.Parent.Humanoid.Health = 0 end end)
It would be greatly appreciated if someone could clear my doubt and explain the code

You check if the parent is a Humanoid, you have to change it from if touch.Parent:IsA(“Humanoid”) then to if touch.Parent:FindFirstChild(“Humanoid”) ~= nil then
You check if the touched part’s parent is a humanoid, but it would usually come as either workspace or a model, so you add FindFirstChild() which (in case returns nil) won’t stop, so you check if it’s not nil (if it’s not nil it must be true) and then you killl the Player

1 Like
local part = script.Parent

part.Touched:Connect(function()
    if touch.Parent:FindFirstChild("Humanoid") then
        touch.Parent.Humanoid.Health = 0
    end
end)

You checked if touches parent is the humanoid. The mistake was that you had to check the parent for a child named Humanoid.

1 Like

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