So I have this script for a health bar:

wait(1)

local plr = game.Players.LocalPlayer
local hum = game.Players.LocalPlayer.Character.Humanoid


hum.HealthChanged:connect(function(health)
	script.parent.Size = UDim2.new(health/hum.MaxHealth,0,1,0)
end)

And it works until your health changes. Then it goes off the screen horizontally and vertically. Any help?

4 comments

0

try using vector2 instead of UDM

0

do I use vector2 for X or Y? the bar is horizontal on the screen

0

i tried it for both, it says "X cannot be assigned" or "Y cannot be assigned"

0

try changing line 8 to script.Parent.Size = UDim2.new(0, health/hum.MaxHealth, 0, 10)