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

Can someone explain UDim2 or how move a GUI?

Asked by 9 years ago

I need someone to explain how to used a UDim2 or how to move a GUI?

2 answers

Log in to vote
0
Answered by 9 years ago

UDim2.new is for moving GUI. for use it you need to said wich frame you'll move or size.UDim2.new use fourth value one for the Position of X for the Scale, the second is for the X too but for the Offset, the third is for the Y Scale and finally the fourth is for the Y but for the Offset -->(XScale, XOffset, YScale, YOffset).

If you want know more about UDim2.new you can go on Roblox wiki here Exemple here:

local screenGui = Instance.new("ScreenGui", script.Parent)--script.Parent mean in the PlayerGui
local frame = Instance.new("Frame", screenGui)
frame.Size = UDim2.new(0, 10, 0, 10)--(XScale, XOffset, YScale, YOffset)
frame.Position = UDim2.new(0, 100, 0, 200)--(XScale, XOffset, YScale, YOffset)

Don't forgot to put this script in the StaterGui if you take this code

Ad
Log in to vote
0
Answered by 9 years ago

Adding onto Toon's answer, if you want it to move/slide to a position use TweenPosition!


How To Tween

You need to get the basic idea on how UDim2 works. After you use the TweenPosition method you need to call some arguments.

  1. The first is where you want the gui to slide to, you use a UDim2 value for this.
  2. The easing direction are Out, In, or InOut. Out means it speeds up when it gets close to the destination. In means it slows down when it gets to the end. InOut means it goes to the position as fast as it can at the beginning, then slowing down to a halt.
  3. Next is EasingStyle. This is the style the gui will be moving at. Quad is okay, I personally like Quint and Back the best. You can find the rest of the styles here.
  4. The 4th is how long it takes to slide in seconds.
  5. The next one is override. If this is true then you can make it tween to a different position while it is tweening. If it is false, you need to wait for the tween to be over, and then you tween it again.
  6. Is callback. I do not know what this is other than it is normally nil and that it's a function that returns a void.

Tween Example

local gui = script.Parent.Frame.TweenGui

gui:TweenPosition(UDim2.new(0,50,0,400), "Out", "Back", 5, false, nil)
--Moves gui to 0,50,400 in 5 seconds

Other Forms of Tweening

  • TweenSize; Change the size of a gui
  • TweenSizeAndPosition; Changes the size and position of a gui
  • TweenService; Service used to tween guis


Hope it helps!

Answer this question