How do i fix gui bar extending?

I making a healthbar and i made a health script, but the health keeps extending
Screen Shot 2021-03-08 at 8.06.30 AM
How do i fix this?

wait(0.2)
while true do
	local hp = game.Players.LocalPlayer.Character.Humanoid.Health/250
	script.Parent.Parent.Indicator.Text = game.Players.LocalPlayer.Character.Humanoid.Health.. "/"..game.Players.LocalPlayer.Character.Humanoid.MaxHealth
	script.Parent:TweenSize((UDim2.new(hp,0,0.6,0)),Enum.EasingDirection.In,Enum.EasingStyle.Quad,0.15)
	wait(0.2)
end

Your bar is extending because the power is too high, set the power to more lower until it fits, and in this case, if you want it to still be 250, you will have to deal with extending all of it

1 Like

which part do i set lower?

1 Like

The health power/how much health a player has

What’s the X size of your HealthBar frame?

1 Like

I didn’t think of resize, wow that would make more sense

the healthbar frame x-size is 0.7

Hey,

I might be wrong so, you might want to scale your gui so it shows the same from the server and the client from mobile and pc: [Plugin] AutoScale Lite for GUIs - Scale your UI - #222 by megmavens5

I usually use that.

Firstly, I think you’re better using the HealthChanged event of the Humanoid instead so it only calls the code when they have been damaged, rather then every fifth of a second. Another thing you should do to fix this is to make the gui update with respect to the original X scale of the GUi at max hp

Try This

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local frame = script.Parent
local indicatorText = frame.Parent.Indicator

local xSize = frame.Size.X.Scale --Getting the original size

hum.HealthChanged:Connect(function(newhp)
	local actualhp = math.floor(newhp) --Doing this since the hp given is a long decimal stream
	local newSize = (newhp/hum.MaxHealth) * xSize
	indicatorText.Text = newhp.. "/"..hum.MaxHealth
	frame:TweenSize((UDim2.new(newSize,0,0.6,0)),Enum.EasingDirection.In,Enum.EasingStyle.Quad,0.15,true)
	wait(0.2)
end)

Edit: Fixed the code for an issue that most likely is gonna appear about indicatorText

Thanks it works