My original username (riorex18) was a combination of my name, my favourite Star Wars: The Clone Wars character's name, and my birthday.
EmeraldSlash came from me liking emeralds and the colour green.
TheDeadlyPanther came from me liking panthers
Meta tables (explained simply and to the point). Honestly, the wiki and all other records I've encountered of meta tables are too hard to follow and understand.
Also a proper tutorial would be nice in general, since the wiki pretty much makes all beginners averse to the complex concepts.
There's actually a Trello board with a ton of suggestions that people vote on. There are already a few of them that have been actually completed.
I've lost it, though, so I will try and find it again.
So, you want to 'tween' a part?
The answer is
:lerp() is a method found in Vector2, Vector3, Color3, and CFrame values. The following parameters are used when calling it:
value1- The first value to use, it is what you call the method on
value2- The second value to use
alpha- The position between these two values to return (number from 0-1 that can be a decimal)
It is used to return the defined position (the
alpha) inside the two given instances of the value type (
To explain this in more simple terms, if I have the numbers
2, and the alpha was
0.5, the method would return
1 (this won't actually work because lerp is not available for numbers). If the alpha was
1, it would return
2 - and if it was
0, it would return
local vector1, vector2 = Vector3.new(0,0,0), Vector3.new(0,2,0) local position = 0.5 local newVector = vector1:lerp(vector2,position)
newVector would be equal to
Now that we have lerp down, next comes on how we actually move the part.
local part = script.Parent local startPosition = part.Position local desiredPosition = Vector3.new(10,10,0) for i = 0,1,0.005 do part.Position = startPosition:lerp(desiredPosition,i) wait() end
Firstly, you set the start and desired positions as values (make sure the start position does not change!).
Next, you setup the for loop. You can use lerp anywhere, but I'm using the for loop because of its simplicity.
The for loop iterates 200 times (the number used as the step is
1/howeverManyTimesYouWantItToMove, which in this case is 0.005), and when it reaches the 200th iteration (AKA
1), the part will be at the
waits() for a very short time - the default wait time, because of how many iterations there are (because you don't want to wait 200 seconds for it to reach it's target, do you?)
There you go, you're part is now moving smoothly (or at least as smooth as you made it)!
If you have any questions or comments, please ask/say them below.
Good luck on your scripting journey ~TDP
:lerp()which lays the groundwork for interpolating each value type.
Not recommended for beginners.
This is a basic tutorial to help you make your code as optimised as possible. It will cover the most commonly encountered situations.
I apologise for my code formatting, Tab currently does not work in the text editor, so I will have make do with nothing until I find something better.
Indexing isn't too much of a problem - the differences optimising it will make are so small humans probably won't notice it. But, it is still an improvement, and all improvements count.
local Vector1 = Vector3.new(0,1,0) local Vector2 = Vector3.new(0,2,0)
When you index something, the computer "grabs" whatever you told it to. Of course, your arm would eventually get tired if you are grabbing something a number of time (let's imagine you put it back when you're done with it).
See how I'm indexing
Vector3.new twice? Well, we could decrease the effect on the computer by simply indexing it once. To accomplish this, we simply define Vector3.new as a variable.
local Vector3New = Vector3.new -- Did you know you can index normal functions without parentheses?
Then, we just call it like usual:
local Vector3New = Vector3.new local Vector1 = Vector3New(0,1,0) local Vector2 = Vector3New(0,2,0)
You can even define the entire library (for indexing global libraries can also weaken that arm):
local Vector3Library = Vector3 local Vector3New = Vector3Library.new
This is relevant to (and based around) objects and tables.
There we go, you have no released a small amount of stress from your computer (or whatever else is doing the computing)!
This is a bit self explanatory, but instead of running more than one instances of the same code, you can just stick the code in a function and call it whenever you need it!
for i = 1,10 do print(i) end for i = 1,10 do print(i) end
See how you're doing this twice? Why not stick it in a function!
function printToTen() for i = 1,10 do print(i) end end printToTen() printToTen()
You can even define parameters to it, so it can do different things;
function printToNumber(startNumber,endNumber) for i = startNumber,endNumber do print(i) end end printToNumber(1,20) printToNumber(12,60)
One thing to always do is keep your formatting clean (see this tutorial for a start). It will help you - and others - to read through your code quickly and easily.
When defining variables, people usually start off by simply defining them;
myNumber = 1
It can be accessed from anywhere in the code, even before it has been defined (this will return an error if you try and index it before it's been defined, time-wise).
It also causes a small amount of inefficiency, so you may want to eradicate it.
To do this, simply define it locally;
local myNumber = 1
Note that with locals, you won't be able to access it out of its 'tier' (as I like to call them).
local myNum = 1 if true then myNum = 2 end print(myNum)
if true then local myNum = 2 end print(myNum) -- throws an error, because it has only been defined withing the if statement
The world of ROBLOX Lua is at your fingertips! Use it!
 This is considered micro-optimisation, and should only be used if performance is flagging.
Hopefully this short tutorial helped you make everything in your code more efficient. If you have any questions, or comments, please ask/discuss them below.
Good luck on your scripting journey!
Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.