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

How do i make a custom Health GUI?

Asked by 9 years ago

I made a Frame across the screen at the very top and inside that frame i want the health Frame to go up and down as the player loses health/ Gains health Now, Unfortunately. I have no idea where to start.

1 answer

Log in to vote
0
Answered by 9 years ago

This is some things to help: 1. Changed; see if something changed 2. UDim2.new; like Vector3.new but for guis 3. TweenSize; to make your gui look better 4. Simple Math; math sucks but in lua, it's your best friend.


Changed

sees if a property of an object changes:

workspace.Part.Changed:connect(changed)
    print("Part's "..changed.." to "..workspace.Part[changed]) --If you change the name to bob you get:
--"Part's Name changed to bob"
end

You can use this on a Humanoid to see if the health changes


UDim2.new

is like a Vector4. It looks like this: UDim2.new(0,0,0,0) UDim2 is like this: X Scale, X Offset, Y Scale, Y Offset.

local gui = script.Parent
gui.Size = UDim2.new(1,0,1,0) --Fill up whole screen

If you do this the size will look like this: {1,0},{1,0}.


TweenSize

It's kinda complicated and you might need to read about it here, TweenSize is optional though.


Math

You need to divide the Health divided by the MaxHealth: 50/100 = 0.5 = Half health. This is also optional, but it would be useful, so that if you have 5000 MaxHealth you don't need a 5000 pixel wide gui How to use it? Take the Health and divide by the MaxHealth, take that number and multiply it by the size of the health bar if it was full health. EXAMPLE: 50 Health; 100 MaxHealth 50/100 = 0.5 0.5*300(300 pixel wide gui) = 150 pixels



Hope it helps!

Ad

Answer this question