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

My health bar was working perfectly, but then it stopped working, why?

Its a localScript in a frame, in another frame, and there is a text label that says the percentage, it worked very good before, but now it isn't working, i dont know why because i can't see any errors, what was broken this time? -.-

local P = game:GetService("Players").LocalPlayer

local C = P.CharacterAdded:wait(1)

local H = C:WaitForChild("Humanoid")

H.HealthChanged:connect(function()

script.Parent:TweenSize(UDim2.new(1/(H.MaxHealth/math.floor(H.Health + .5)),0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce,1)

script.Parent.Parent.percentage.Text = tostring(math.floor(100/(H.MaxHealth/H.Health)).."%")

end)

thanks for help this new scripter -.-

6 comments

0

Could you explain what changes you made that caused it to stop working or at least say what it's doing instead of working?

0

I'm no pro. But if you tried to print out some of the variables, you might be able to see the issue.

0

BlueGrovyle, i did nothing, it just doesn't work anymore, i think that a roblox update has broken it.. and Tweak, variables isn't the solution for everything

0

Put a print statment every couple lines to see where it stops printing then you know where the problem is.

0

smart idea

0

i finded the error.. it was because the script wasn't finding the humanoid, because i used FindFirstChild instead of WaitForChild

1 answer

You don't divide 1 / XYZ or 100 / XYZ. You just divide the MaxHealth by the Health.

This will return a value within the range of 1 to 0, which is a perfect fit for the Scale property of a UDim2 value. You can plug this into a UDim2 by doing this:

GuiObject.Size = UDim2.new(Humanoid.MaxHealth/Humanoid.Health, 0, 1, 0)

Also, Math.floor() cannot be used to round decimals. It only floors to the nearest whole number, which for a decimal sub-one, is zero.

1 comment

0

i already solved the problem and that wasn't the problem.. it just wasn't finding the Gui, and the Player char for some reason, i fixed it.. so, its ok now, thx

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