Pages

Friday, July 27, 2012

A Small Scripting Tutorial: UDim2.new

So, a lot of people have been asking me to make a scripting tutorial. I never actually agreed. But people were saying RN were low on some scripting tutorials, so I may continue doing this in the future if people find them helpful.

What is UDim2?
UDim2 is like the CFrame of a gui, with UDim2 you can move guis and manipulate them to your willing. Like Quadratum Havoc, when you press 'Q' a gui flies into the screen. This is one of the great things you can create with the object UDim2.

How do we use UDim2?
UDim2 is actually not that hard to use in the slightest, as long as you have a text button, and a script with a function. You can move it anywhere.

A script involving UDim2:
function ZakaryIsEpic(mouse)
script.Parent.Parent.TextButton.Position = UDim2.new(0.5, 0, 0.5, 0)
wait()

script.Parent.Parent.TextButton.Position = UDim2.new(0.6, 0, 0.6, 0)
wait()

script.Parent.Parent.TextButton.Position = UDim2.new(0.7, 0, 0.7, 0)
wait()
end


script.Parent.MouseButton1Click:connect(ZakaryIsEpic)
The Function Line: The function line is just the function. (HAS TO HAVE MOUSE)


UDim2, the UDim2.new line would make the TextButton have the position {0.5, 0, 0.5, 0}.


The wait line makes it wait the lowest it can, (wait(0.03)).
The end line ends the function


And the connect line connects the function.


But what if we don't want to write this much?
Well, problem solved, we have the for function...


function ZakaryIsEpic(mouse)
       for i=0.01, 0.5, 0.01 do
              script.Parent.Parent.TextButton.Position = UDim2.new(0+i, 0, 0+i, 0)
              wait()
       end
end


script.Parent.MouseButton1Click:connect(ZakaryIsEpic)


Instead of writing every line of code to do it, you can just use for. This code would make the textbutton move 0.01 every 0.03 second, and it would move many, many times a second. It would have to move to 0.5, so it would move around 500 times. For can also be used for other things like transparency, but I won't get into detail with that on my first scripting tutorial on ROBLOX News.


I'm Zakary99 and thank for for reading this tutorial.
Want news on my latest projects/posts?
Follow me @RBX_Zakary99

No comments:

Post a Comment

Write your comment here... OR Flingi will eat you