Uploaded by vlad

Scripting Secrets Cheat Sheet

advertisement
Scripting Cheat Sheet Document
Here is your scripting cheat sheet with all the basics from SmartyRBX’s easiest
beginner guide to scripting video (plus extras from Scripting Secrets!). This will be
incredibly useful even if you haven't seen that video.
To use this resource to its maximum ability, refer back whenever you’re scripting to access all of the
important concepts when needed.
Stay tuned for more extremely valuable resources sent to your email inbox shortly.
Good luck on your scripting journey!
Introductory Scripting Concepts:
1. Variables
a. A variable stores a value
b. Define a variable with "local"
c. Example: "local PinkPart = script.Parent"
2. Creating a new part with scripting
a. Use "Instance.new()"
b. Example: "local Part = Instance.new("Part")"
3. Setting part properties
a. A part has properties that can be changed
b. Example: "Part.Parent = game.Workspace" sets the parent of the part to the Workspace
c. Example: "Part.Transparency = 0.5" sets the transparency of the part to 0.5
d. Example: "Part.Anchored = true" sets the anchored property of the part to true
4. Booleans
a. A boolean is a value that is either true or false
b. Example: "Part.Anchored = false" sets the anchored property of the part to false
5. Strings
a. A string is a line of text
b. Example: "print("Hi")" prints "Hi" in the output window
6. Wait function
a. Waits a certain amount of time before moving to the next line
b. Example: "wait(1)" waits for 1 second
c. In modern scripting, its best to use the updated "task.wait()" for improved performance
7. Math
a. Math can be performed in scripts
b. Example: "print(3 + 4)" prints the sum of 3 and 4 in the output window.
8. Functions
a. Functions are blocks of code that perform a specific task
b. Example:
c. function addNumbers(num1, num2)
return num1 + num2
end
9. Events
a. An event is a signal that something has happened
b. Example:
script.Parent.Touched:Connect(function(part)
print("Part touched: " .. part.Name)
end)
10. Loops
a. A loop repeats a block of code a certain number of times or until a condition is met
b. Example: for i = 1, 5 do
print(i)
end
11. If Statements
a. An if statement is used to check a condition and execute code if the condition is true
b. Example:
c. if game.Players.LocalPlayer.Health <= 0 then
print("You have died.")
d. end
12. Operators
a. Operators are symbols that perform operations on values. These are similar to math
symbols, but there are some additional ones and changes done to the ones you are
familiar with to be fit to programming.
b. Example:
i.
print(5 + 2) -- addition operator
ii.
print(5 == 2) -- equality operator (returns false)
13. Tables
a. Tables are a data structure that can store multiple values in one variable
b. Example:
local myTable = {"apple", "banana", "orange"}
print(myTable[2]) -- prints "banana"
14. Conditional statements
a. Conditional statements execute a block of code only if a condition is met
b. Example: "if Part.Anchored == true then
print("The part is anchored")
else
print("The part is not anchored")
15.
16.
17.
18.
19.
end"
c. prints "The part is anchored" if the part is anchored and "The part is not anchored" if it
is not anchored
Functions
a. Functions are blocks of code that can be called later and return a value
b. Example: "function add(a, b)
return a + b
End
print(add(3, 4))"
c. prints 7 in the output window
Tables
a. Tables are a data structure that store information
b. Example: "local player = {Name = "John", Age = 20, Health = 100}" creates a table with
the player's name, age, and health
Event connections
a. Event connections allow scripts to react to events, like a player clicking a button
b. Example:
"script.Parent.MouseButton1Click:Connect(function()
print("The button was clicked")
end)"
c. prints "The button was clicked" when the parent object of the script is clicked by the
player.
Commenting
a. Use double hyphens (--) to add comments to your code.
b. Comments are useful for explaining what your code does and can help other
programmers understand your code.
c. Example: "-- This function adds two numbers and returns the result"
Debugging
a. Debugging is the process of finding and fixing errors in your code.
b. Use print statements to help you debug your code by displaying the value of variables
or the output of a function.
c. Example: "print(myVariable)" will print the value of myVariable in the output window
Helpful Scripting Videos:
The EASIEST Beginner Guide to Scripting (Roblox)
How to Script Easily & Remember Everything (Roblox)
Official Roblox Documentation:
Documentation - Roblox Creator Hub
Enjoy the Cheat Sheet!
Hope this helps you in your development journey. As I mentioned earlier, I’ll be sending you more
useful things your way shortly. In the meantime…
Can I tell you about another opportunity?
Having trouble finding everything online and searching for info?
It can be very difficult when you are starting in scripting.
I sure know it was for me,
Sitting there, tearing my HAIR OUT over code not working
And solutions that were never found.
I remember writing notes trying to string together some sort of HOPE.
This cheat sheet is the first step..
But will you take the second step?
Take your next step today and skip the frustration.. (and go straight towards success!)
👉 smartyrbx.com/next-step
Download