Answered by
8 years ago Edited 8 years ago
Hi, I can see you've done a lot of number crunching to create your GUI, but there is a much simpler way to move GUI's or resize them without using a for
loop.
Here's an example of a script I created that moves a GUI from off screen to on screen.
02 | shop = button.Parent.Shop |
05 | button.MouseButton 1 Click:Connect( function () |
08 | shop:TweenPosition(UDim 2. new( 0.5 ,- 250 , 0.5 ,- 100 ), "Out" , "Quad" , 1 ) |
11 | shop:TweenPosition(UDim 2. new( 0.5 ,- 250 ,- 0.5 ,- 100 ), "Out" , "Quad" , 1 ) |
If you'll notice, instead of using for
loops to change the position, I use a cool API called TweenPoisition()
. What it does is essentially animate the GUI from where it is to where you give the UDim2.new()
position.
Let's say I had a GUI sitting of screen so it's location was (-0.5,0,0,0) and I wanted to move it into view for the player to see. The first step would be to define what the GUI is that you're moving. In my case it's a frame titled Shop.
Next you want to give the location that you want it to take the GUI to.
1 | shop:TweenPosition(UDim 2. new(- 0.5 , 0 , 0 , 0 )) |
That's not all though. We can also set the styles of the wait the GUI eases in our out, or both. As well as setting the EasingStyle for how it'll look sliding. I like to pick Quad for this one. (Here is an animated list Roblox made of all the different easing styles.)
1 | shop:TweenPosition(UDim 2. new(- 0.5 , 0 , 0 , 0 ), "Out," , "Quad" ) |
You can also set how long it takes for the animation to float to the end point. It's default is one second.
1 | shop:TweenPosition(UDim 2. new(- 0.5 , 0 , 0 , 0 ), "Out," , "Quad" , 1 ) |
You can also use TweenSize() to tween the size instead or do both position and size with TweenSizeAndPosition()
You can read more about Tweening on the wiki page here.