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

Decal to a Health Bar?

Hello there, I am wondering if anyone knows how to create a health bar from a decal. I have created a heart on photoshop which is red and another heart which is grey and I want to code it so that it when I lose health it will go down showing the grey heart depending on how much damage the player took. I've made the image work using a frame and enabling ClipsDecendants and can operate it only when shrinking the frame and it makes the grey heart visible. I have tried to make a code to automatically show the grey heart but all my scripts are just not working. I was trying yesterday for 4 hours but had no luck at all. If anyone can help with this please get back to me as soon as possible. Thanks! :D

5 comments

0

Do you want it to be a decal attached to a part or part of the player's UI that shows up on screen?

0

spoilt brat

0

what?

0

jack15783, calm down..

0

Hello Lyphios, I would like it to appear on the StarterGUI so it stays on the screen at all times when the player is playing the game.

1 answer

So first, copy the texture ID on the red heart decal. Then, make an ImageLabel in a screengui in StarterGui, and paste the id into the ImageLabel, resize and change the background transparency. Leave this one visible. Now copy and paste the ID of the grey heart into a new ImageLabel in the same ScreenGui and resize it to the same size( or whatever you want ) and change the BackgroundTransparency, and set this image to Visible = false, which will be in the properties tab of the ImageLabel. Now name the Red Image to "red" or whatever you want, and the grey one to "grey". So now make a LocalSCript inside he ScreenGui that detects when the player's health is below 10(or to your desired health level), and when the player's health is below 10, the script should do something like:

local Red = script.Parent.Red
local Grey = script.Parent.Grey
--some code I won't write for you, do it yourself

Red.Visible = false
Grey.Visible = true

I didn't write the code in the middle, because I'm not about to babysit you. Do that part yourself but use this as the base code. The properties tab is your friend.

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