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

I try to make a Health Bar Script and I get an Error, what does it mean?

Asked by 5 years ago

I'm a beginner to coding and I'm trying to make a Health Bar script like the one below:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Human = Character:WaitForChild("Humanoid")
local HealthFrame = script.Parent

Human.HealthChanged:Connect(function(Health)
    HealthFrame.Size = UDim2.new(HealthFrame/Human.MaxHealth,0,1,0)
end)

But then I get an error like this:

Players.Klydefiss.PlayerGui.HealthStaminaUI.OuterFrame.HealthFrame.HealthBar.HealthScript:7: attempt to perform arithmetic on upvalue 'HealthFrame' (a userdata value)

I don't understand what arithmetic or upvalue means, So it would be nice if someone could explain to me what this error means.

0
You're dividing the frame object (HealthFrame) with a number on line 7. Did you mean to type in just "Health"? User#20279 0 — 5y
0
No, I had watched a scripting tutorial and I typed just as I saw it Klydefiss 0 — 5y
0
Oh, I see what you mean, I'm trying to divide an Object by a number. I understand now. Klydefiss 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Human.HealthChanged:Connect(function(Health)
    HealthFrame.Size = UDim2.new(HealthFrame.Position.Scale.X/Human.MaxHealth,0,1,0)
end)
Ad

Answer this question