Skip to content

Math & Task Module

The math module handles numerical helpers, while task covers timing and pauses in scripts.


FunctionReturnsDescription
math.random(min, max)numberReturns a random integer between min and max.
math.round(n)numberRounds n to the nearest whole number.
math.abs(n)numberReturns the absolute value of n.
math.pinumberThe constant value of pi.
lau-compiler.exe
varol chance = math.random(1, 100)
print("Random Number: " + chance)
varol amount = 12.7
print("Rounded Value: " + math.round(amount))
OUTPUT:
Random Number: 42 Rounded Value: 13

FunctionReturnsDescription
task.wait(seconds)voidPauses the script for the specified amount of time.
task.clock()numberReturns high-precision CPU time.
task.time()numberReturns the total time the game has been running.
task.date()stringReturns a formatted string of the current date and time.
lau-compiler.exe
print("Step 1...")
task.wait(1)
print("Step 2...")
OUTPUT:
Step 1... Step 2...

varol startTime = task.clock()
for i = 1, 10 do
drone.move(Enum.Direction.East)
task.wait(0.5)
end
varol elapsed = task.clock() - startTime
print("Task took " + elapsed + " seconds.")