Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

3 comments

0

You're dividing the frame object (HealthFrame) with a number on line 7. Did you mean to type in just "Health"?

0

No, I had watched a scripting tutorial and I typed just as I saw it

0

Oh, I see what you mean, I'm trying to divide an Object by a number. I understand now.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.