My killpart isn't working

So I am currently making a ROBLOX obby and I want to insert a Kill Part, that kills you on touch.

script.Parent.Touched:Connect(function(hit)
	if hit and hit.parent and hit.parent:FindFirstChild("humanoid")then
		hit.parent.humanoid.health = 0
	end
end)

This is the script I have come up with, with the help of a tutorial. I have tested my game and it isn’t working when I touch the part. Any assistance would be greatly helpful.

You can just use:

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

The ‘if hit and hit.parent and’ in your code is unnecessary.
Also make sure wherever you reference ‘Parent’ you use a capital letter at the beginning.

I can’t give you any further technical insight since I’m not a godlike scripter, but the above code works fine.

1 Like

You need a capital H for both Humanoid and Health

1 Like

Hello, you need to use capitalization, you cannot keep these words lowercase.

Here is a basic solution:

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")

        if Humanoid then
           Humanoid.Health = 0
        end
end)
```

I did this and it works.

script.Parent.Touched:Connect(function(hit)	
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:BreakJoints()
	end
end)

Thanks everyone! Really helped!