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

How do I like to put in a script for Enemy Health Bar Depletion?

I'm making a very small group for me and my friends, and I want to add enemy health bar GUI, but all the tutorials I watched so far involves player GUI. How do I not only display enemy health bar GUI using Billboard, but make it deplete? I have no experience in Scripting, this is my first so I would appreciate some explanation or a full script.

5 comments

0

I have done this before, I will provide you with a full tutorial when I get home.

0

Thank you, please be as soon as possible.

0

If you've never scripted or have 0 experience in scripting, then I wouldn't recommend starting off with this.

0

Well, I really have no choice, I want to build a sort of D&D my friend likes to play, so I want to add health that can be damaged but also can be seen, cause normal Humanoid health is not big enough.

0

We are scripting helpers not scripting writers. Bring your problems here for us to help you with. Don't have us create a whole new script for you. I will be taking moderation.

1 answer

✓ Accepted answer

hierarchy = NPC > Head > BillBoardGUI > Frame1 > Frame2 > Script. BillboardGUI will be obviously the billboard. Set this to where you want, and the size you want. Frame 1 will be your health bars background. I typically set this to a dark red color. Frame2 will be the frame that shows how much hp is left. I typically set this to a bright red color. Script will be where the script to move Frame2 is located.

humanoid = script.Parent.Parent.Parent.Parent.Parent.Humanoid
script.Parent.Parent.Parent.Parent.Parent.Humanoid.Changed:Connect(function()
	wait(.1)
	local hp = humanoid.Health / humanoid.MaxHealth
	script.Parent:TweenSize(UDim2.new(hp,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
end)

Make sure that you set frame2's ZIndex to a higher value so that it actually appears above Frame1. This script should work. I haven't tested it inside a game itself, but studio worked. Any issues just comment back and i'll try to work them out.

6 comments

0

Thanks I finally got the bar to go down, but the Red Background is not appearing!

0

I recently been getting "Humanoid is not a valid member of Workspace"

0

Gui's are listed by Zindex. The lower the value, the lower the "layer" Make sure that frame2 has a higher zindex than the rest, so that it appears above them. As for the Humanoid error, that means that the script isn't in the same parent as what I used.  You can fix this by changing the first line to direct to the humanoid. 

0

Here is a picture of my hierarchy for refrences https://imgur.com/a/pdfrjwY

0

Is this wrong? https://imgur.com/S7ELDV0

0

No that is correct. It may possibly be because the script is loading before humanoid is, causing it to error and not try again. Try adding this to the top of the code. script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Humanoid")

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