Trying to make a NPC break a weld on damage

So I’ve been trying to get a humanoid to break a weld when the humanoid has 75 health or less.
but it still don’t work,
If you can help me wih my issue I will be thankful.

Last try
local humanoid = script.Parent:FindFirstChild("Humanoid")
while humanoid do
	if humanoid.Health <= 75 and humanoid.Health > 1 then
		script.Parent.ok.weld:Destroy()
		print("ok")
	end

end
image

But my last code makes output say this:
image

Your script needs to have a wait() or else it would run forever all on a single frame which the game doesn’t like. Thats why you get an error.

Instead of using a while loop, you can use the Humanoid.HealthChanged event, this would turn your script into

local humanoid = script.Parent:FindFirstChild("Humanoid")
humanoid.HealthChanged:Connect(function(NewHealth)
	if NewHealth <= 75 and NewHealth > 1 then
		script.Parent.ok.weld:Destroy()
		print("ok")
	end
end)
2 Likes