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

Why am I getting this Health error?

Asked by 8 years ago

This is in a normal script in the StarterGui Any ideas why I am getting this error?

attempt to index field 'Health' (a number value)

Code:

script.Parent.Parent.Character.Humanoid.Health.Changed:connect(function()
if script.Parent.Parent.Character.Humanoid.Health == 0 then 
script.Parent.Parent.TeamColor = script.Col.Value 
script:Destroy()
end
end)




I hadn't had any problems with it up until recently :/

1 answer

Log in to vote
0
Answered by 8 years ago

The Changed event is a part of the Humanoid, not of it's Health property.

Fix:

script.Parent.Parent.Character.Humanoid.Changed:connect(function()
    if script.Parent.Parent.Character.Humanoid.Health == 0 then 
        script.Parent.Parent.TeamColor = script.Col.Value 
        script:Destroy()
    end
end)
Ad

Answer this question