My gui size keeps changing because of the script

Here is the video that explains my problem:

Please tell me what is changing the size of my gui.
Script:

wait(0.2)
while true do
	local hp = game.Players.LocalPlayer.Character.Humanoid.Health/100
	script.Parent:TweenSize((UDim2.new(hp,0,1,0)),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.15)
	wait(0.2)
end
2 Likes

I wouldn’t say i’m expert scripter, but…

I am guessing its because of the TweenService, usually making health bars are not that simple. It’s my best guess. I wouldn’t say i’m 100% right.

The tweenservice might be thinking that your saying to please resize the ui to this and that.

2 Likes

If you can’t fix the problem by changing the script, Get an auto scale plugin. You can find a tutorial on where to find, and use one.

Your problem is most likely it’s not set to scale. You can do it manually but using a plugin is much easier. Scale plugin using this plugin you need to set the scale position and the scale size and thag should fix your issues.

The plugin doesn’t work sadly.

1 Like

Did you make sure to scale the position and size of all the frames and the text label?

Yes I did. I even watched tutorials on how to use it but none of them helped.

1 Like

Could it be that it’s moving outward? Do you need to be tweening it at all, if not try disabling the script and see if it doesn’t move at all,

Whenever I delete or disable the script, the gui goes back to normal.

1 Like

Alright. Is that not what you wanted? The script is causing it to change, if you don’t want it to change just keep the script disabled or remove it. What are you trying to accomplish?

The script moves the bar like it’s supposed to and that’s what I want. To show how much health is left. The script if also changing the size of the gui so now I’m thinking of writing a different script to do the same thing.

1 Like

UDim2.new(hp,0,0.5,0) or UDim2.new(hp,0,0,0)
maybe change it to this or the other thing

I already tried that and it didn’t work but I’ll try the 1st option.

This made it thinner but a bit longer than expected. I’ll work with that. Thank you.

No clue why you’re doing a while true do loop, I think it can be fixed though if there’s no offset?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local YSize = script.Parent.Size.Y.Scale --I'm guessing is where it could be? This is just to prevent the Y UI from changing size

Character.Humanoid.HealthChanged:Connect(function()
     local Scale = Character.Humanoid.Health / 100
    script.Parent:TweenSize((UDim2.new(Scale, 0, YSize, 0)), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.15)
end)
1 Like

It might be because you did hp,0,1,0 where the 1 is making it bigger in height

You should make the 1 smaller so it becomes the size you want

The script fixes the size but it doesn’t shrink when I get damaged.

1 Like

Strange, maybe it’s the Scaling that could be the issue? Or the way the UI is parented

There seems like one issue with your solution, you forgot .Scale because Size.Y has two properties .Scale and .Offset
UDim2 | Documentation - Roblox Creator Hub as displayed in the docs on UDim2.