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

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

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.

2 comments

0

Frame = UDim2.new(0,playerHP*3.45)... try that maybe?

0

try my script again

1 answer

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)

1 comment

0

I have encountered a different problem now. It does change the frame size, but it changes in the vertical axis, not horizontal.

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