BreakJoints Problem

So, I was trying to make a Script where whenever I touch a part I basically die but the problem is that whenever I touch a part I don’t die but my legs just breaks or something but just don’t die.

Here’s the video if you don’t know what I mean:

Here’s the code:

local lava = workspace.Lava
lava.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit:BreakJoints()
	end
end)

I think you need to do, hit.Parent:BreakJoints(), right now hit would be a body part that touched the lava, you need to get the body that has that body part, so the Parent

1 Like

Yes, I realized it after I made the post

1 Like

I think you should also be aware that anything under the character impacts the touch event when you use hit.Parent. My suggestion is to use the hierarchy features that roblox has given for you.

local BasePart = script:FindFirstAncestorWhichIsA("BasePart")

BasePart.Touched:Connect(function(HitInstance)
	if HitInstance:FindFirstAncestorWhichIsA("Accoutrement") or HitInstance:FindFirstAncestorWhichIsA("BackpackItem") then
		return
	end
	local Character = HitInstance:FindFirstAncestorWhichIsA("Model")
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

	if Humanoid:GetState() ~= Enum.HumanoidStateType.Dead and Humanoid.Health > 0 then
		Humanoid:TakeDamage(Humanoid.MaxHealth)
	end
end)

And I wouldn’t suggest Model:BreakJoints because that’s what Humanoid:TakeDamage is there for. It’s also because dealing damage rather than breaking joints may meet other script expectations such as custom deaths and etc.

2 Likes