Cheatography
https://cheatography.com
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.random(x,y) |
Returns a random number between x and y |
math.floor(x) |
Rounds down x |
math.ceil(x) |
Rounds up x |
math.abs(x) |
Returns the absolute value of x |
math.sqrt(x) |
Returns the square of x |
math.pi |
Returns pi |
|
|
Basic Refrences
.game |
Parent of all running game services |
.workspace |
Refrences Workspace, circumvents game.Workspace |
.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.wait() |
Pauses the execution of the script for a set duration. More acurated, Independent of framerate. |
task.delay() |
Runs a function after a specified delay but does not block the current script. |
RunService.Heartbeat |
Creates a custom wait loop. High precision, frame-dependent tasks. |
Debris:AddItem() |
Used for timed object destruction but can act as a timer mechanism. |
Basic Threading
task.spawn() |
Runs a function in a new thread after yielding briefly (~1/30th of a second) |
task.defer() |
Schedules a function to run in a new thread without yielding at all. It is executed after the current thread completes. |
coroutine.create() |
Creates a new coroutine that is paused until explicitly resumed. |
coroutine.resume() |
Resumes a paused coroutine. |
coroutine.yield() |
Pauses the current coroutine until it is resumed again. |
coroutine.status() |
Returns the status of a coroutine ("suspended", "running", or "dead"). |
coroutine.wrap() |
Creates a coroutine and returns a function that, when called, resumes the coroutine. |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets