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

Scripting a GUI scaling but it sets to a default size?

Asked by 5 years ago

So, i'm working with a gui right now. I am trying to script a Udim2.new() script so that it changes the size of the GUI when certain event are activated.

But, whenever i test the game, it automatically sets the X-scale of the GUI to 1. Even tho i did not script it to be that way.

Can someone please help me?

Here's the code:

script.Parent.Size = UDim2.new(char.Humanoid.Health / char.Humanoid.MaxHealth,0,590,0,31)
0
the UDim2.new function only has 4 arguments, you gave it 5. radusavin366 617 — 5y

1 answer

Log in to vote
1
Answered by
RAYAN1565 691 Moderation Voter
5 years ago
Edited 5 years ago

The UDim2.new(number xScale, number xOffset, number yScale, number yOffset) has a maximum of four parameters.

A scale has a maximum value of 1 and is a percentage of the player's screen. 1 being 100% of the screen size and 0 being 0% of the screen size.

Also to keep updating the health bar, you must use a while true do loop.

Below, you will find a script that I think should solve your problem:

while true do
    wait()
    script.Parent.Size = UDim2.new((char.Humanoid.Health*0.1)/char.Humanoid.MaxHealth,0,0.02,0)
end
Ad

Answer this question