I am making parts in my game simulate a humanoid in a way. I put a health value in each part (partinstance).
When the the part's health value changes.. I put a enable the Parts "Health bar Billboard Gui".
I get the health's percent by doing local percent = math.floor(Health.Value/MaxHealth*100)/100
I then use the percent variable here. "green" is the green overlay frame you usually have on health bars. The green overlay will vary in size depending on the percent of health.
green.Size = UDim2.new(percent, 0, 1, 0)
green.Position = (UDim2.new(0, 1 - percent, 0, 0)), "Out", "Quad", 1, false, nil
However, the only thing the script isn't doing is exactly that. My test prints stop at those lines and does not give any other errors. Am I doing this incorrectly?
Here is my hierarchy of the Billboard Gui. http://prntscr.com/7vyoc0
Here is my full script.
local MaxHealth = 100
HealthDisplay = game.ReplicatedStorage.HealthDisplay:Clone()
function AddHealthModule(partinstance)
local Health = Instance.new("IntValue", partinstance)
Health.Name = "Health"
Health.Value = MaxHealth
local display = HealthDisplay:Clone()
display.Parent,display.Adornee = partinstance,partinstance
local percent = math.floor(Health.Value/MaxHealth*100)/100
local green = display.back.green
Health.Changed:connect(function()
local display = Health.Parent.HealthDisplay
display.Enabled = true
display.back.HealthTxt.Text = "Health"..Health.Value.."/"..tostring(MaxHealth)
green.Size = UDim2.new(percent, 0, 1, 0) --Doesn't work?
green.Position = (UDim2.new(0, 1 - percent, 0, 0)), "Out", "Quad", 1, false, nil --Neither does this
if Health.Value <= 0 then
partinstance:Destroy()
elseif Health.Value > MaxHealth then
Health.Value = MaxHealth
display.HealthDisplay.Enabled = false
end
end)
end
return AddHealthModule

1 comment
Guess that's what happens when you code at 2:00 AM, Heheh. Thanks. :)