Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

.Changed function not working on a Number Value?

Asked by 8 years ago
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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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)
    ....
0
Thanks ! Great Help! Bubbles5610 217 — 8y
Ad

Answer this question