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

why is this script giving me an error?

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

It says "attempted to index 'Health' (a number value)" and I do not know what to do to get rid of this error. Basically I am trying to display the characters health on a local gui.

local player = script.Parent.Parent.Parent.Parent.Parent.Parent

player.Character.Humanoid.Health.Changed:connect(function(health)
    script.Parent.Text = health.."%"
end)

1 answer

Log in to vote
0
Answered by
AZDev 590 Moderation Voter
8 years ago

I didn't see where you defined health. You need to either declare health or point to The proper location.

Try changing health(where you set the text) to

player.Character:FindFirstChild("Humanoid").Health

Sorry if I got anything wrong I am using a phone with spell correction.

0
I just notices you used health as a param. I don't think that is a param. I could be wrong though AZDev 590 — 8y
0
it works when I print it, if i say print(player.Character.Humanoid.Health) it will print my health coolblockman22 5 — 8y
0
Try using player.Character.Humanoid.Health then. AZDev 590 — 8y
Ad

Answer this question