0% found this document useful (0 votes)
514 views

Roblox: General Scripting Cheat Sheet: by Via

This cheat sheet summarizes Roblox scripting concepts including: 1) Essential objects like Parts, Models, and Scripts and their descriptions. 2) Basic math, string, and table functions. 3) How to create and access objects, properties, and methods like Clone(), FindFirstChild(), and WaitForChild(). 4) Event basics like connecting scripts to events using functions.

Uploaded by

Nenad Milosevic
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
514 views

Roblox: General Scripting Cheat Sheet: by Via

This cheat sheet summarizes Roblox scripting concepts including: 1) Essential objects like Parts, Models, and Scripts and their descriptions. 2) Basic math, string, and table functions. 3) How to create and access objects, properties, and methods like Clone(), FindFirstChild(), and WaitForChild(). 4) Event basics like connecting scripts to events using functions.

Uploaded by

Nenad Milosevic
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Roblox: General Scripting Cheat Sheet

by Ozzypig (Ozzypig) via cheatography.com/25526/cs/6711/

Essential Objects Basic math functions (cont) String functions (cont)

Class Desc​rip​tion math.floor(n) Rounds n down. string.sub(str, Return sub-string of


a, b) str from a to b.
Part A physical brick in the world. math.ceil(n) Rounds n up.

Model A container for Parts. math.abs(n) Returns absolute value of A string is a collection of charac​ters, or text. An

Folder A container for Scripts and value n. example of a string property is the Name
objects. property. Read all string manipu​lation functions
math.sqrt(n) Returns square root of n.
here.
Script A container for Lua source code.
math.pi Approx equal to 3.14159
LocalS​cri A Script that runs its code on a
Tables
pt client. It's important to work out problems by hand
before transl​ating their solutions into code. local list = {1, 2, 3}
Algebra is necessary for success. Read about
Basic math functions local firstNum = list[1]
all math functions here.
Oper​ation Desc​rip​tion list[2] = 4
print(​"​There are " .. #list .. "
a + b Adds a and b. String functions
number​s")
a - b Subtract a and b. Oper​ation Desc​rip​tion local total = 0
a * b Multiply a and b. a .. b Combine two for i = 1, #list do
strings. ​ ​ ​total = total + list[i]
a / b Divides a by b.
Func​tion Desc​rip​tion end
a % b Remainder of a divided
string.len(str) Returns length of print(​"The total is " .. total)
by b.
str.
Tables are a collection of values. They are
Func​tion Desc​rip​tion
string.upper(str) Returns str in defined using curly braces {} with values
math.random(n) Returns random number separated by commas. Access the values
upper-​case.
from 1 to n (no inside using square brackets []. Tables are
string.lower(str) Returns str in
negati​ves). sometimes called arra​ys. Use a for loop to
lower-​case.
math.random(a, Returns random number work with all items in a table indivi​dually. The
string.reverse(str) Returns str in :GetCh​ild​ren() method returns a table of
b) from a to b.
reverse. children in an object.
math.max(...) Returns the largest
string.rep(str, n) Returns str
number.
repeated n times
math.min(...) Returns the smallest
number.

By Ozzypig (Ozzypig) Published 25th January, 2016. Sponsored by CrosswordCheats.com


cheatography.com/ozzypig/ Last updated 24th January, 2017. Learn to solve cryptic crosswords!
ozzypig.com Page 1 of 3. http://crosswordcheats.com
Roblox: General Scripting Cheat Sheet
by Ozzypig (Ozzypig) via cheatography.com/25526/cs/6711/

Constants Creating objects (cont) Event basics

game Parent of all game services. How do I copy a preexi​sting object? function onTouch(part)

Using objec​t:C​lone() and setting the ​ ​ ​pri​nt(​par​t.Name .. " touched


workspace Container for all bricks and
models are stored. parent: me!")
newTree = workspace.Tree:Clone() end
script The currently running script.
newTree.Parent = workspace worksp​ace.Pa​rt.T​ou​che​d:c​onn​ect​(on​To
uch)
Finding Objects
General Object Functions
workspace.Part:Destroy() Events are specific occurr​ences relating to

Method name Desc​rip​tion objects. When an event fires, or occurs, all


print(​scr​ipt.Pa​ren​t.Name)
connected functions are called.
game.S​erv​erS​tor​age.Tr​ee:​Clone() :FindFirstChild(name) Return a child
with name or
Use a period to access an object's children. Use Basic functions
nil if it doesn't
.Parent to access an object's parent. Use
exist. wait(n) Wait n seconds then continue.
constants like game, workspace, and script to
identify objects in the hierarchy. :WaitForChild(name) Pauses until a print(...) Display something in the
child with a Output window.
Creating objects name exists
and returns it. Variables
How do I create an object?
:IsA(className) Return whether
Using Insta​nce.ne​w(c​lass) and local myScore = 5
the object is a
setting the parent: myScore = myScore + 1
certain type of
object.Parent = parent object. print(​myS​core)
local myName = "​Ozz​y"
How do I access an object's proper​ties? :Clone() Makes and
print(​"My name is " .. myName)
returns a copy
Use a period (.):
of an object. Variables store data of any kind - numbers,
print(object.Name)
:Destroy() Perman​ently strings, tables, objects or nil (nothing). A local
How do I set an object's proper​ties? delete an variable is only accessible in the block of code
Use a period (.) and equals sign (=): object. it is defined in.
part.Transparency = .5 :GetChildren() Return a list of
an object's
How do I destroy an object?
children.
Using objec​t:D​est​roy()
These are functions (aka methods) for all
classes of ROBLOX objects. Read about all
methods here.

By Ozzypig (Ozzypig) Published 25th January, 2016. Sponsored by CrosswordCheats.com


cheatography.com/ozzypig/ Last updated 24th January, 2017. Learn to solve cryptic crosswords!
ozzypig.com Page 2 of 3. http://crosswordcheats.com
Roblox: General Scripting Cheat Sheet
by Ozzypig (Ozzypig) via cheatography.com/25526/cs/6711/

If statements Loops Function examples

if workspace:FindFirstChild("Tree") Numeric for loop function sayHello()


then For counting numerically. ​ ​ ​pri​nt(​"​Hello, world")
​ ​ ​pri​nt(​"​There is a tree here.") Example: Count from 1 to 5: end
end for i = 1, 5 do sayHello()
if coins < 5 then print(i) func​tion addTwo​Num​bers(a, b)
​ ​ ​pri​nt(​"You need more money."​) end ​ ​ ​pri​nt(​"The sum is:", a + b)
else end
Generic for loop
​ ​ ​pri​nt(​"You have enough money!​") addTwo​Num​bers(3, 5)
Most often used for object children.
end func​tion calcul​ate​Squ​are(n)
Example: Print all children in object:
if player.Name == "​Jak​e" then ​ ​ ​ r​eturn n * n
for i, child in
​ ​ ​pri​nt(​"You are an awesome guy, end
pairs(object:GetChildren()) do
Jake") local result = calcul​ate​Squ​are(3)
print(child.Name)
elseif player.Name == "​Sal​ly" then
end A function is a named block of code that can
​ ​ ​pri​nt(​"You are a sweeth​eart, be run anywhere in code by call​ing it by
Sally") While loop
name. Functions can have argu​ments (given
else Perform code until a condition is false. values) and/or return values.
​ ​ ​pri​nt(​"You are a pretty cool Example: Remove all children named 'Ball'
while
person​")
object:FindFirstChild("Ball") do
end
object.Ball:Destroy()
If statements will run their code if the value
end
between if​/​then is true (or not nil). They can
one an else block, or any number of elseif Repeat​-until loop

blocks. Perform code once, then again until a


condition is true.
Ex.: Copy objects until there are 5.
repeat
newObject = object:Clone()
newObject.Parent = workspace
wait(1)
until #workspace:GetChildren()
>= 5

Loops are used to iter​ate, or repeat code a


number of times.

By Ozzypig (Ozzypig) Published 25th January, 2016. Sponsored by CrosswordCheats.com


cheatography.com/ozzypig/ Last updated 24th January, 2017. Learn to solve cryptic crosswords!
ozzypig.com Page 3 of 3. http://crosswordcheats.com

You might also like