I Need Help With A Custom Health Bar

Okay, crossing my fingers that this is the last time I need to post about help with this game I am making. If you haven’t seen my last few posts, I am making a small game to practice my scripting skills. Today, I went to make a custom health bar, but soon got very stuck trying to script it. What I want it to do is for you to click a button at a certain time, and it shrinks 2 studs. I want it so that every time you click the GUI text button, the part shrinks 2 studs. Can you all help me with this? I have provided some pictures below. Thank you!

Here is the health bar

Here it is in Studio

If you need any more pictures or explanation, just ask! Thank you once again!

(If you couldn’t tell, I am not a professional scripter, just FYI)

1 Like

Could we see your script? I wanna know what’s wrong with the script

1 Like

If you try to code the script we can help you :slight_smile: But you haven’t provided any yet.


Okay. I do not have much right now, I mostly just need a script but if you come up with one, here is what it would be going into.


That is what the script would be going into. I basically need a script so that the health bar can shrink 2 studs when you click the Text Button at a certain point.

I haven’t really made that much of a script for the bar, but I have made the script I am implementing the other script into. (Pictured in my latest reply)

Wait are you asking for a script ?

Pretty much. I am not really a great scripter, so I really need all the help that I can get. Even some hints to how I could accomplish this would be nice. This is all a learning thing for me.

I believe you could place the red part of the bar inside the container for the bar, make sure the container has ClipsDescendants enabled, and just tween the red bar a certain distance to the left based on when the button is clicked.

A custom health bar should be a GUI generally. Specifically you should use a Billboard Gui (not a part)

Inside the billboard gui you probably want a frame, and that frame will represent the health. You can then use basic math in order to change the size


local root = script.Parent.Parent 
local clickDetector = script.Parent -- For input
local gui = root .Parent.BillboardGui -- Billboard gui
local healthBar = gui.HealthBar -- Frame

local health = 100 
local maxHealth = 100
local damage = 5

   health -= damage
   healthBar.Size = Udim2.new(health / maxHealth, 0, 1, 0)
   -- Color effects or whatever
1 Like

Thank you for the help! It isn’t exactly a health bar though. I honestly just need a script that will take 2 studs off a part and will repeat that every time you click the text button. Thank you though!

Ah ok, well in that case just use something like this

local part = workspace.Part
   part.Size = part.Size - Vector3.new(0,2,0) -- x,y,z 
1 Like