Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with a Health bar lowering when the actual health gets lower (GUI)?

Asked by
Ghost40Z 118
4 years ago

I am making a game with my friends and since most people are busy, I am having to do almost everything coding related even though I am not very good at it.

I am trying to make some kind of GUI Health bar, and I wrote a script with the purpose of making a frame smaller on the X-axis when the health lowers. However, the script doesn't work and I don't know why.

local Frame = script.Parent.Frame.Frame.Size.X
local playerHP = game.Players.LocalPlayer.Character.Humanoid.Health

while playerHP > 0 do
    Frame = playerHP*3.45 -- Multiplier is 3.45 because that's the size of the frame
end

I also need help with making the GUI visible to each player individually, so that when someone else takes damage, the other players' health bar doesn't change.

Thanks in advance.

0
Frame = UDim2.new(0,playerHP*3.45)... try that maybe? greatneil80 2647 — 4y
0
try my script again User#29913 36 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

So you will need a few things: Frame, LocalScript, and ScreenGui. Insert the Frame and the LocalScript into the ScreenGui. Position the Frame however you want. Then make this in the LocalScript (EDITED BECAUSE OF VERTICAL):

local frame = script.Parent:WaitForChild("Frame")
local char = script.Parent.Parent.Parent.Character

char:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
    frame:TweenSize(UDim2.new(frame.Size.X.Scale,frame.Size.X.Offset,frame.Size.Y.Scale,char.Humanoid.Health))
end)
0
I have encountered a different problem now. It does change the frame size, but it changes in the vertical axis, not horizontal. Ghost40Z 118 — 4y
Ad

Answer this question