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
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) ....