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

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

Asked by 5 years ago

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 -.-

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? BlueGrovyle 278 — 5y
0
I'm no pro. But if you tried to print out some of the variables, you might be able to see the issue. Tweakified 117 — 5y
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 darkzerobits 92 — 5y
0
Put a print statment every couple lines to see where it stops printing then you know where the problem is. GottaHaveAFunTime 218 — 5y
View all comments (2 more)
0
smart idea darkzerobits 92 — 5y
0
i finded the error.. it was because the script wasn't finding the humanoid, because i used FindFirstChild instead of WaitForChild darkzerobits 92 — 5y

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago
Edited 5 years ago

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:

lua 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.

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 darkzerobits 92 — 5y
Ad

Answer this question