Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

.Changed function not working on a Number Value?

local Mob = script.Parent.Parent.Parent.Parent.Parent:FindFirstChild("Human")


Mob.Health.Changed:connect(function()

i was just wondering why the health variable didnt work, and someone could explain .Changed functions in a bit more depth? (aparantley this is a number value and doesnt work?) and also is it possible to make it work? ~thx , Bubs

1 answer

✓ Accepted answer

Mob.Health is just a number, e.g., 100.

100 doesn't change. Furthermore, numbers don't have properties. You can't ask for 100.blah because that doesn't make sense -- numbers don't "have" things. They just are.


ROBLOX decided which objects get to do what. .Changed isn't something "special" in Lua. It's just the name that a lot of objects give for an event that fires whenever something happens to them. Parts or Humanoids have it. Lua doesn't -- so numbers don't.

If you want to wait for the health to changed, you have to connect to Mob's Changed event. You get the name of the property that was changed:

Mob.Changed:connect(function(property)
	if property == "Health" then
		.....

There also happens to be a HealthChanged property on humanoids:

Mob.HealthChanged:connect(function(newhealth)
	....

1 comment

0

Thanks ! Great Help!

This discussion is preserved as it was. New answers, comments, and votes are closed.