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

How do I change the X value of a GUI?

I want to change the X value of a GUI/Frames position with a script* but I do not know how. Thank you for any help.

2 answers

✓ Accepted answer

#How to get a GuiObject's X position: (original post)

To simply get a GuiObject's X position is by getting the Position then typing in .X. Your code should look like this:

game.Players.LocalPlayer.PlayerGui.Gui.GuiObject.Position.X

Although I am assuming, but you may not want the Offset for the X and most likely you would want the Scale property for X. To simply get scale, you can do this:

game.Players.LocalPlayer.PlayerGui.Gui.GuiObject.Position.X.Scale

To change the x position do the following:

local = game.Players.LocalPlayer.PlayerGui.Gui.GuiObject.Position


#edit by royaltoe

just adding on to what p0vd said, Gui's positions are read only. You can change the position of anything inside a gui such as frames/button/label etc. though.

As an example, let's say I have this script directly inside of my gui and I have a frame inside that gui.

Here's how I'd change the frame's position to be in the middle of the screen:

local gui = script.Parent 
local frame = script.Parent.Frame

frame.Position = UDim2.new(.5,0,.5,0)

To change only the x value, you'd do the following:

local gui = script.Parent 
local frame = script.Parent.Frame

--change the frame's position to be 50% of the screen in the X-Axis, leaving everything else about the position the same. 
frame.Position = UDim2.new(
						.5, 
						frame.Position.Offset.X,
						frame.Position.Scale.Y,
						frame.Position.Offset.Y,
					)

You see, the ROBLOX Frame scaling goes by the x,y order, like a graph in math. So when you look at the property "Size," it will show something like this... {0,0},{0,0}. The 1st set of numbers is the x axis, and the second set is the y axis. Just change the 1st set of numbers and you are done. By the way, in each axis, the 1st number represents the whole number and the second represents the decimal. But, this graph only spreads to 1. So to have a full screen, do {1,0},{1,0}. Just remember that fact and hope this answer helps!

2 comments

0

Thank you for trying to help but I wanted to know how to change the X value on a frames position via script. It is my fault for not specifying, I have edited it.

0

use the UDim2.new() constructor

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