Alright so I a making a menu with GUI's and I want to make this button more efficient so I can change it if needed without going through tons of work:
function roll() script.Parent.Parent.TextBox.Position = UDim2.new(-0.25,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.24,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.23,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.22,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.21,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.20,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.19,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.18,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.17,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.16,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.15,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.14,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.13,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.12,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.11,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.10,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.09,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.08,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.07,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.06,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.05,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.04,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.03,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.02,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(-0.01,0,0.25,0) wait(0.001) script.Parent.Parent.TextBox.Position = UDim2.new(0,0,0.25,0) wait(0.001) end script.Parent.MouseButton1Click:connect(roll)
Hello DarkNinja,
An easier way to move would be using the TweenPosition method.
What is TweenPosition? TweenPosition is a method in which a player can move a GUI, and make it look smooth. It makes all the code you have pasted go easier.
How to use TweenPosition?
TweenPosition to start, is only with GUIs, and you would use a UDim2 value.
Example script:
GUI = script.Parent GUI:TweenPosition(UDim2.new(X.Scale, x.Offset, y.Scale, y.Offset, Out, "Quad", 3, true)
Breakdown:
Out is the EasingDirection.
In = Applies the transition in reverse.
Out = Applies the transition normally.
InOut = Applies the transition in reverse, then normally.
Quad is the EasingStyle
Linear = Stays the same speed throughout the process of tweening. The speed is determined by the time argument.
Sine = Gradually slows down until the end point is reached. Main speed is determined by the time argument.
Back = Once the GUI reaches its target point, it will go over it just a bit (depending on the time argument), and then return to the target position.
Quad = Starts off fast and gradually slows down after the GUI reaches 1/4 of the way towards the end point.
Quart = Starts off fast and gradually slows down after the GUI reaches 3/4 of the way towards the end point.
Quint = Starts off fast and gradually slows down after the GUI reaches 1/2 of the way towards the end point.
Bounce = Bounces off the end point a couple times (speed depends on the time argument) and returns to the end position.
Elastic = Acts as if the GUI were being stretched like rubber and then launches towards its end point.
3 is how long it will take it to move. 1 is the default. Here it's set to three.
True allows you to control whether tweens can be interrupted. This will make the GUI will start moving to the right side of the screen, but when it's halfway there it'll start another tween which moves it to the bottom.
True = Can be interrupted
False = Can't be interrupted
function roll() for i = -0.25, 0, -0.1 do script.Parent.Parent.TextBox.Position = UDim2.new(i,0,0.25,0) wait(0.001) end end
This is a more efficent way of doing it but you can use :TweenPosition as well.
http://wiki.roblox.com/index.php/TweenPosition_(Method)