Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make this fit in the bottom right corner regardless of window size?

I'm trying to figure out how I can make this ImageLabel fit in the bottom right corner of a player's screen, regardless of their window size. How would I do that?

	local helmet = script.Parent.Helmet
	helmet.Position = UDim2.new(0.9, -422, 0.8, -156)
	helmet.Size = UDim2.new(0, 100, 0, 100)
	helmet.Visible = true

1 answer

There is an equation you can use to get a GUI to be in the bottom right corner of the player's screen.

gui.Position = UDim2.new(1, -gui.AbsoluteSize.X, 1, -gui.AbsoluteSize.Y)

Since we know the size of the X and Y values of the helmet GUI will always be 100 pixels since you've set it in the script, we can just do the following for the helmet GUI's position:

helmet.Position = UDim2.new(1, -100, 1, -100) --Places GUI in the bottom right corner, regardless of window size.

What if we used Scale for the size instead? Well, we just use the AbsoluteSize property instead. AbsoluteSize is a property that has a Vector2 value that shows how big the GUI is on the player's screen.

helmet.Position = UDim2.new(1, -helmet.AbsoluteSize.X, 1, -helmet.AbsoluteSize.Y) --Places GUI in the bottom right corner, regardless of window size.

There is one problem with your code when doing this. If players re-size their game window, the GUI would not move to match the new game size window in game. This will be fine when using the offset values of a UDim2, but when using the scale values, you will need to keep changing the position to reflect the AbsoluteSize difference.

You could use events such as the Changed event to make this work.

helmet.Changed:connect(function() --Anonymous function for the Changed event. An anonymous function is essentially writing a function in an event's connection line.
	helmet.Position = UDim2.new(1, -helmet.AbsoluteSize.X, 1, -helmet.AbsoluteSize.Y) --Places GUI in the bottom right corner, regardless of window size.
end) --Closing parenthesis to fully wrap the function in the connection line.

I hope my answer helped you. If it did, be sure to accept it.

2 comments

0

I'm confused on the last part for AbsoluteSize.X and Absolute.Y

0

When your screen size changes and you're using scale for size, if you don't update the GUI's position, it won't fit. AbsoluteSize just reflects how big the GUI is on your screen in pixels. You won't need to worry about this for your GUI though.

This discussion is preserved as it was. New answers, comments, and votes are closed.