Trouble getting the character to die after a value is changed to 0

PLEASE READ THE FULL POST, I MENTION SOMETHING AT THE BOTTOM!

I’m trying to make a health system for a game I’ve been making (aka. the Super Check Point parody if you’ve seen my last post) and I can’t quite seem to get the player to die after the HP value changes to 0. This is what I keep getting in the output:

image

This is the script I’m using:

wait(0.5)
local humanoid = script.Parent.Parent
while true do
	if humanoid.HP.Value < 1 then
		humanoid.Health = 0
		wait(0.25)
	end
end

I’m considering using a changed function, I’ll be trying it while I wait for replies. Thank you for reading!

This post explains it in detail. Hope it helps!

I didn’t see that, sorry! I’ll look at that post, if it’s about the :Changed function, I’m already trying that. :slight_smile:

Oh, it’s not! I’m already trying the Changed function, will that work?

No its abt the error u get in the output and lik u know a long explanation on it.

1 Like

That depends on how u want to do it. If u want to use Changed, u r free to do so, however if want to figure the error and possibly fix the script, i wud recommend reading the post.

1 Like

I’d rather use :Changed, thank you though! I’ll mark it as a solution if it works.

1 Like

It’s working! Thank you very much!

1 Like

Sure i hav nothing against it, it is ur freewill to choose which method to implement.

1 Like

Glad to hear it :smiley: ignore ignore

1 Like

It’s .Changed but yes, that will be a lot more efficient than running an infinite while true do loop waiting for a value to change.

local humanoid = script:FindFirstAncestorWhichIsA("Humanoid")
local hp = humanoid:WaitForChild("HP")

hp.Changed:Connect(function(new)
	if math.round(new) <= 0 then
		humanoid.Health = 0
		task.wait(0.25)
	end
end)