There are some obscure features in roblox luau that can save lots of time, but they are barely known. Let’s change that.
Vector3
Do you ever find yourself always writing Vector3.new(0, 0, 0)
or Vector3.new(5, 5, 5)
And just wished there was an easier way to do this? Yes there is. Vector3.zero
and Vector3.one
exists.
local object: Part = workspace.Part
object.Size = Vector3.one * 50 -- Vector3.new(50, 50, 50) but shorter and more efficient.
object.Position = Vector3.zero -- Puts the part in Vector3.new(0, 0, 0)
Okay, I also wished there was an easier way to write Vector3’s like Vector3.new(20, 0, 20)
You are in luck. It also exists, Vector3.xAxis
, Vector3.yAxis
and Vector3.zAxis
Here is how I do it:
object.Position = (Vector3.xAxis + Vector3.zAxis) * 20
-- or
object.Position = (Vector3.xAxis + Vector3.yAxis) * 20
-- order dosent matter as these are vector3s
object.Position = (Vector3.yAxis + Vector3.xAxis) * 20
However, there are some cases where Vector3.new
is cleaner, for example Vector3.new(50, 0, 20)
, these constants are not for ditching Vector3.new
Math
Lets talk about math.random
. Ever find yourself tired from math.random(1, 5)
, math.random(1, 10)
and so on?
You are in luck. math.random(n)
picks a number from 1 to n
object.Position = Vector3.one * math.random(20)
-- another example
object.Position = (Vector3.xAxis + Vector3.zAxis) * math.random(20)
How clean! Without knowing this we would write Vector3.new(math.random(1, 20), math.random(1, 20), math.random(1, 20))
. How ugly!
And that’s all I know for now. Hopefully this helped, even in the slightest.
Suggest more obscure features in the replies!