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

How would I code this health bar?

I have absolutely NO idea on how to code this health bar. I have an idea on how to do a normal one, but what's special is that it's not a single bar; it's multiple bars. Here's what I mean: http://prntscr.com/8de5ez

Each bar stands for 5 health, as a ROBLOX character has 100 health and there are only 20 bars on the GUI.

**I need to know the method to display the character's health in terms of 20 bars (I believe that it will be 0.2 of the health at any given time, but I am not sure.) **

I have close to know idea where to start. Here is what I have so far:

game:service'StarterGui':SetCoreGuiEnabled("Health",false)

local gui = script.Parent
local container = gui.Container
for index, child in pairs(container:GetChildren()) do
    print(child.Name) --This is just to log all the bars in Container. Container is the frame which has
--all of the 20 bars in it. 
end
local showing = gui.Showing
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local maxhealth = humanoid.MaxHealth
local health = humanoid.Health

showing.Value = health


I have a NumberValue called "Showing" to track how many bars should be showing, but I'm not sure how to script it so that the number of bars showing is equal to the NumberValue.

Does anyone have an idea on how do this?

1 answer

humanoid.HealthChanged:connect(function()
showing.Value = health
end)

1 comment

0

By default, I've set Showing to 0. However, when I kill my character, the value changes to 100. 

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