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

Gui's are changing size on bigger and smaller screens. Help?

Asked by 6 years ago
Edited 6 years ago

I have this small code for a health bar: It's in a local script

local player = game.Players.LocalPlayer
local health = player:WaitForChild("Humanoid").Health
player.Humanoid.Changed:connect(function()
script.Parent.Size = UDim2.new(0,health*3.6,2,0)
end)

What this does is make the size of the bar the number of health the humanoid. But if I made the bar only 100 it would be too small so I added the health*3.6 to make it look normal. In my screen it's perfect but in other peoples screens it only appears half the bar. I tried using a plugin but it didn't work. Is there any way to make my script know how full the bar needs to be relatively to the player's health? Like for it to be full when the health is 100 and half when the health is 50. Some sort of calculation, or something I am missing.. Sorry if this is a dumb question I just can't seem to figure it out.

Thanks for whoever helps me with this! :)

0
I recommend to use Size.Scale instead Size.Offset Bazuxk 95 — 6y

1 answer

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago

Before you view my answer, I noticed a few small problems in the script. If you fix these it may fix the script, so try fixing these first:

-The Humanoid isn't a member of Player, it's a member of Player.Character. When getting the Humanoid, use Player.Character:WaitForChild("Humanoid") instead.

-You can't determine when a number value is changed. A Humanoid's Health is a number value. Instead, determine when the Humanoid itself is changed. Basically instead of using just health, use Humanoid.Health.

The script at the end of this should fix some of your problems in case you don't get what I'm saying.


The basics of UDim2 in Gui is this (If you already know it then just skip the next two paragraphs):

-The first and third number is the X and Y relative to the screen. For example, if I scripted TextLabel.Size = UDim2.new(1,0,1,0), the TextLabel would cover the entire screen. if I instead typed (0.5,0,0.5,0), then it'd cover half of the screen.

-The second and fourth number is the X and Y relative to pixels. If I instead used TextLabel.Size = UDim2.new(0,100,0,100), it'd make the TextLabel exactly 100 pixels long and 100 pixels wide.

The stuff above is critical to making something like a health bar that changes size. I recommend using the first and third numbers in UDim2 when making something like a health bar. If you put this script into your health bar, it should work:

local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.Changed:connect(function()
script.Parent.Size = UDim2.new(Humanoid.Health/10, 0, 0, 50)

0
I forgot to put the .Character when writing that,sorry. But i'll try to do that wilsonsilva007 373 — 6y
0
I changed a bit of the script to: script.Parent.Size = UDim2.new(0,Humanoid.Health/10,2.3,0) Because the bar was insanely big, but there's something wrong with the "Humanoid.Health/10" because it would only size only 1/10 of the bar. How do I fix that? wilsonsilva007 373 — 6y
0
That is only the problem left really. wilsonsilva007 373 — 6y
0
Never mind. I managed to fix it and now It works perfectly! Thanks my dude! wilsonsilva007 373 — 6y
Ad

Answer this question