|
| 28 Jun 2016 05:39 PM |
I'm trying to make an HP ScreenGui for players. I'm trying to make it so when the health goes down, it go back up. The green health bar extends far beyond the the screen by x axis whenever the health is changed, which is not what I wanted. Please help me fix this.
Script:
local Figure = game.Players.LocalPlayer.Character local Humanoid = Figure.Humanoid local Gui = script.Parent local regening = false
----------------- --Fire Function-- ----------------- function regenHealth() Gui.Size = UDim2.new((Humanoid.Health / Humanoid.MaxHealth),0,0.014,0) if regening then return end regening = true while Humanoid.Health < Humanoid.MaxHealth do local s = wait(1) local health = Humanoid.Health if health > 0 and health < Humanoid.MaxHealth then local newHealthDelta = 0.01 * s * Humanoid.MaxHealth health = health + newHealthDelta Humanoid.Health = math.min(health,Humanoid.MaxHealth) end end if Humanoid.Health > Humanoid.MaxHealth then Humanoid.Health = Humanoid.MaxHealth end regening = false Gui.Size = UDim2.new((Humanoid.Health / Humanoid.MaxHealth),0,0.014,0) end
Humanoid.HealthChanged:connect(regenHealth)
while true do wait() script.Converter.Value = Humanoid.Health script.Parent.Parent.HP.Text = "["..Figure.Name.."] ["..script.Converter.Value.."/"..Humanoid.MaxHealth.."]" end
|
|
|
| Report Abuse |
|
|
|
| 28 Jun 2016 05:42 PM |
| The default character rig already comes with health regeneration. If I were you I'd edit that. Just have the gui listen to the Humanoid's changing health value. It's generally a bad idea to manipulate stuff like health from the client anyway. |
|
|
| Report Abuse |
|
|
|
| 28 Jun 2016 05:44 PM |
| Never mind. Forget the part where I said it makes the health regen. The bar still extends beyond the screen when changed though. |
|
|
| Report Abuse |
|
|
|
| 28 Jun 2016 05:46 PM |
Well here's how I do it:
Make a container, and put a filler in it, Filler Size : {1, 0, 1, 0}. Container will be the size of the entire bar.
Every time the health changes, Size would be {health/maxhealth, 0, 1, 0}.
You can also change the color of the filler if you want as health gets lower or higher. |
|
|
| Report Abuse |
|
|
|
| 28 Jun 2016 05:51 PM |
| Is container maxhealth, and filler health? |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Jun 2016 08:41 PM |
Yes they are.
Container is whatever size you want.
Filler is the {0, health/max, 0, 0}
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|
|
| 28 Jun 2016 09:49 PM |
Would this work?
local Gui = script.Parent --ImageLabel local Player = game.Players.LocalPlayer local Character = Player.Character.Humanoid
Character.HealthChanged:connect(function() Gui.Size = UDim2.new((Humanoid.Health / Humanoid.MaxHealth),0,0.014,0) end
--Let me know if i'm missing anything. Thanks DiamondBladee! |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
Lem0nzzx
|
  |
| Joined: 08 Feb 2016 |
| Total Posts: 1604 |
|
|
| 29 Jun 2016 08:46 AM |
Character.Humanoid.Changed:connect(function() Gui.Size = UDim2.new((Humanoid.Health / Humanoid.MaxHealth),0,0.014,0) end
|
|
|
| Report Abuse |
|
|
|
| 29 Jun 2016 09:04 AM |
local Gui = script.Parent --ImageLabel local Player = game.Players.LocalPlayer local Character = Player.Character
Character.Humanoid.HealthChanged:connect(function() Gui.Size = UDim2.new((Character.Humanoid.Health / Character.Humanoid.MaxHealth),0,0.014,0) end)
This. Still. Won't. Work.
|
|
|
| Report Abuse |
|
|
|
| 29 Jun 2016 10:49 AM |
Why is the Y scale so small?
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2016 12:24 PM |
| Healthbar is very small. The same issue still persists, the health bar gets bigger after health changes. |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2016 12:28 PM |
This is the health bar. Green is health.
https://gyazo.com/6dcfc697d871dca2bc4911f79ccf0df9 |
|
|
| Report Abuse |
|
|
|
| 29 Jun 2016 12:30 PM |
| Can you make a place and invite me to Studio? I think something else is wrong because the solutions should work. |
|
|
| Report Abuse |
|
|
| |
|
|
| 29 Jun 2016 12:50 PM |
Whole Script: local Gui = script.Parent --ImageLabel local Player = game.Players.LocalPlayer local Character = Player.Character
Character.Humanoid.HealthChanged:connect(function() Gui.Size = UDim2.new((Character.Humanoid.Health / Character.Humanoid.MaxHealth),0,0.014,0) end)
--Let me know if i'm missing anything. Thanks DiamondBladee! |
|
|
| Report Abuse |
|
|
| |
|
|
| 29 Jun 2016 12:53 PM |
| https://www.roblox.com/games/423193373/Legends-Of-Taranna-TESTING-REALM |
|
|
| Report Abuse |
|
|
| |
|