Show Menu
Cheatography

Roblox Lua Cheat Sheet by

A simple refrence guide for any studio user who blanks on something

Math Operations

x + y
Adds x and y
x - y
Subtracts y from x
x * y
Multiplys the x by y
x / y
Divides x by y
x % y
Remainder of x divided by y

Math Functions

math.r­and­om(x,y)
Returns a random number between x and y
math.f­loor(x)
Rounds down x
math.c­eil(x)
Rounds up x
math.a­bs(x)
Returns the absolute value of x
math.s­qrt(x)
Returns the square of x
math.pi
Returns pi
 

Basic Refrences

.game
Parent of all running game services
.workspace
Refrences Workspace, circum­vents game.W­ork­space
.script
Refrences the script itself
.parent
Refrences the parent of an object

For Loops

for i = start, end, count do
    --Code
end

for i = 1, 5 do
    print("Iteration:", i)
end

local fruits = {"Apple", "Banana", "Cherry"}
for index, value in ipairs(fruits) do
    print(index, value)
end

While Loops

while condition do
    -- Code
end


local counter = 1
while counter <= 5 do
    print("Count:", counter)
    counter = counter + 1 -- Increment the counter to avoid an infinite loop
end
 

Wait routines

wait()
Pauses the execution of the script for a set duration. Tied to game framerate
task.w­ait()
Pauses the execution of the script for a set duration. More acurated, Indepe­ndent of framerate.
task.d­elay()
Runs a function after a specified delay but does not block the current script.
RunSer­vic­e.H­ear­tbeat
Creates a custom wait loop. High precision, frame-­dep­endent tasks.
Debris­:Ad­dItem()
Used for timed object destru­ction but can act as a timer mechanism.

Basic Threading

task.s­pawn()
Runs a function in a new thread after yielding briefly (~1/30th of a second)
task.d­efer()
Schedules a function to run in a new thread without yielding at all. It is executed after the current thread completes.
corout­ine.cr­eate()
Creates a new coroutine that is paused until explicitly resumed.
corout­ine.re­sume()
Resumes a paused coroutine.
corout­ine.yi­eld()
Pauses the current coroutine until it is resumed again.
corout­ine.st­atus()
Returns the status of a coroutine ("su­spe­nde­d", "­run­nin­g", or "­dea­d").
corout­ine.wrap()
Creates a coroutine and returns a function that, when called, resumes the coroutine.
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Roblox: General Scripting Cheat Sheet
          Roblox: CFrames Cheat Sheet
          Jetbrains Rider - Keyboard Shortcuts Cheat Sheet