Creating a Script | Documentation - Roblox Creator Hub (2024)

Coding is the process of creating instructions for computers to follow. Just like people use different languages, such as English and Spanish, so do programs. Roblox uses the coding language Lua.

This article will cover how to start coding in Roblox, introducing common concepts like scripts, data types, and variables. By the end, you'll be able to type out code that displays messages in Roblox Studio.

Coding with Scripts

In Roblox Studio, lines of Lua code are held in scripts. These scripts give the game sets of instructions on how to give players health points, create a rain of fireballs, or anything else imaginable.

Creating a Script

Scripts are commonly created in ServerScriptService, a special folder made just for holding scripts.

  1. In Explorer, hover over ServerScriptService to see the + button.

    Creating a Script | Documentation - Roblox Creator Hub (1)
  2. Click the + button and select Script. A new script will be created and the script editor will open.

  3. Right-click Script and select Rename. Name the script PracticeScript. Naming scripts helps you and any teammates remember what each script does.

Hello World

New scripts include a print function at the top of the script editor. Print functions display text on the screen. It's one of the first functions many people learn, and you'll use it often. This code will make "Hello world!" appear on the screen.

Default code

print("Hello world!")

To find the script next time you open up Roblox Studio, click on the name of the script above the game editor, or double-click the script's name in Explorer.

Testing Output

You can see the result of running the default code with the Output window. The Output window is typically at the bottom of Roblox Studio, but if you've never used it before, you may need to enable it.

You'll need the Output window throughout this course, so now is a good time to enable it if you haven't already.

  1. Select the View menu tab.

  2. Click Output.

    Creating a Script | Documentation - Roblox Creator Hub (2)

    The window will appear at the bottom of Roblox Studio.

    Creating a Script | Documentation - Roblox Creator Hub (3)
  3. To test the script, click Play. Hello world! will show up in the Output window.

    Creating a Script | Documentation - Roblox Creator Hub (4)
  4. Click Stop to end the playtest. You can now return to the Script tab.

Identifying Data Types

Coding languages classify different kinds of values into data types. For example, one data type is a number. Number data types are self-explanatory as they are made up of only numbers.

Another data type is a string. Strings can hold numbers, letters, and characters. Take another look at the default code in the new script; the words and quotations within the parenthesis is an example of a string data type.

Strings like "Hello World" always sit inside quotation marks, "like this". More examples of strings are below. Notice how they hold a mix of letters and numbers.

  • "You just joined the game!"

  • "There are 50 players left"

  • "10"

Creating Variables

Variables are containers for information the program can use and change, like player names or points.

Declaring a variable is what coders call the process of creating a new variable. In Lua, to declare a new variable, type local, then type the name for the new variable. A variable that can hold a player name might look like: local playerName

When declaring new variables, some coding languages require that you also state what data type the variable can use. For example, a variable in Java would be String name = "Pavel". Lua only requires a name.

In Lua, variables can be global or local. You'll usually use local variables. Local variables can only be used within the script or chunk of code where they were created. Global variables can potentially be used by other scripts, but too many global variables can make your experience slow and unresponsive. It's better to stay in the habit of making variables local unless necessary.

Using Variables and Strings Together

Time to declare your own variables. These steps will use a string to store the name of your favorite animal.

  1. Delete print("Hello world!"). It's best practice not to leave unnecessary code in your scripts.

  2. Declare a new variable by first typing local, then naming the variable myAnimal.

    Declares a new variable

    local myAnimal

Variable names can't include spaces. Be careful not to include spaces or the code won't work as intended.

Naming Variables

Variables can be named anything, but good names will always describe their purpose. Generic names make your code difficult to read and update later. Coders will also use different capitalization styles to remind themselves how the variable is used within the script. A good default style is camelCase.

To write in camelCase:

  • Begin with a lowercase letter

  • Leave out spaces

  • Capitalize additional words

Good Variable Names

  • playerPoints

  • numberStorageArray

Bad Variables Names

  • myVariable - Doesn't describe the purpose of the variable

  • player name - The included space will cause issues

Assigning Values to Variables

New variables are empty. To assign it a value, or put something inside its container, use the = symbol. In this case, assign the variable the name of your favorite animal.

  1. After the variable name, type =.

    Equal assigns values

    local myAnimal =

  2. On the same line, type a string that contains your favorite animal. Remember the quotation marks.

    Assigns "Porcupines" to myAnimal

    local myAnimal = "Porcupines"

Using Print() For Your Own Messages

Print functions display text on the screen, as you saw earlier. It's one of the first functions many people learn since it's a simple way of giving the script a command. To see your variable, use the print() function.

  1. On a new line, type print().

    Adds empty print()

    local myAnimal = "Porcupines"

    print()

  2. Type the name of your variable within the parenthesis.

    Outputs "Porcupines"

    local myAnimal = "Porcupines"

    print(myAnimal)

    If you see a red error in the output editor, it's like there's an error in the code. Each error has a unique way of describing itself. Try and use the information from the error to fix your code.

  3. Test your code with the play button. You should see the name of your animal in the Output window.

Combining Strings

You can display any string in the Output using print(); you can even print multiple strings stored within variables or typed directly within the function. Concatenation is combining strings. To concatenate the string assigned to your variable and a second string, use two dots .. The following example concatenates two variables and two typed strings.

Uses variables and strings together

local firstAnimal = "porcupines"

local secondAnimal = "dolphins"

print("I like " .. firstAnimal .. " and " .. secondAnimal)

Play around with printing different combinations of strings.

Summary

New scripts can be created by clicking the + button next to the name of an object. ServerScriptService is a common place to create new scripts. New scripts include the default code print("Hello world!"). This code will display Hello world! in the Output window, where you can see the results of your code and if any errors have occurred.

"Hello world!" is an example of a string data type. Strings can include any combination of characters that you might type on your keyboard. Concatenation is when multiple strings are combined.

Variables are containers that can be assigned to hold different data types, such as strings and numbers.

Creating a Script | Documentation - Roblox Creator Hub (2024)

FAQs

Creating a Script | Documentation - Roblox Creator Hub? ›

Creating scripts for Roblox can be risky, especially if they involve exploiting or modifying game mechanics in unauthorized ways. Using or distributing scripts that give players unfair advantages or manipulate the game in ways that violate Roblox's Terms of Service can result in account bans or other penalties.

Is scripting legal in Roblox? ›

Creating scripts for Roblox can be risky, especially if they involve exploiting or modifying game mechanics in unauthorized ways. Using or distributing scripts that give players unfair advantages or manipulate the game in ways that violate Roblox's Terms of Service can result in account bans or other penalties.

Does Roblox use C++? ›

In the case of Roblox, C++ is likely used for various aspects of the platform, including: Engine Development: The core engine that powers Roblox games, including rendering, physics, networking, and audio systems, is written in C++.

How to put script on Roblox? ›

In Roblox Studio, hover over ServerScriptService in the Explorer window and click +. Select Script to add a new script. Right-click the script and rename it to HelloScript.

What are Roblox scripts coded in? ›

Code in Roblox is written in a language called Luau which you can put in scripts within various containers in the Explorer. If you put a script under a Part, Roblox will run the script's code when the part is loaded into the game.

Can I get banned for using Synapse? ›

Yes. Using macros or any other similar programs to automatically do things is against the rules and is bannable. You must play the game yourself without the aid of automated processes, such as using a macro to click 5 times at the press of a button.

Does Roblox ban script users? ›

roblox sees rules as black and white and sadly no matter the context if a rule is broken they will issue bans. if you were to just script your own it would be more similar to an admin panel and would be perfectly fine.

Is Roblox scripting hard? ›

Roblox scripting is not as hard to learn as other programming languages might be. But you will need to commit time and effort. How long it takes to learn Roblox scripting is not an easy question to answer, because it all boils down to how much effort and time you put into it.

What was Roblox originally called? ›

The beta version of Roblox was created by co-founders David Baszucki and Erik Cassel in 2004 under the name DynaBlocks. Baszucki started testing the first demos that year. In 2005, the company changed its name to Roblox.

Does Roblox use Lua or Luau? ›

Luau is the scripting language creators use in Roblox Studio. It is a fast, small, safe, gradually typed embeddable scripting language derived from Lua 5.1. Contributing your Luau scripts for AI training can help enhance Luau-focused AI tools in Studio.

Is Roblox easy to code? ›

Roblox Studio uses Lua as its scripting language because it is easy to learn, fast, and flexible. Lua is a scripting language that is widely used in the gaming industry, and it is well-suited to being embedded in other applications.

Which Roblox game was the first to reach 1 billion visits? ›

Binello is noted for his development techniques, which include playing the game on alternate accounts to gauge the reactions of new players. MeepCity was the first game on Roblox to pass 1 billion total visits.

Is Lua easier than Python? ›

Kids who have studied both languages with FunTech tend to say that Lua is easier to learn than Python. However, as with any type of coding, it's down to opinion and experience.

Is it OK to use scripts in Roblox? ›

Using script executors are against the Roblox TOS, so even thought you are using it for good, it still counts as an exploit. I remember seeing a ban message for 4-7 days for somebody being banned for exploiting.

Is it legal to exploit in Roblox? ›

Exploiting or cheating is unfair to all Roblox players and creates a poor experience for everyone. These actions are a violation of the Roblox Terms of Use, and will lead to the deletion of an account.

Can you get banned for using scripts in Roblox private server? ›

You will only get banned if you are caught running scripts a game is not supposed to have (very rare). The reason why this is very rare for Roblox to do is because every game is a world and it's hard to determine whether it was a hack, a bug, a lag issue, a glitch, a feature, etc…

Can you get hacked from using scripts in Roblox? ›

Hackers are not able to edit, nor even view most scripts, anything that isn't local to the player can not be edited nor even viewed by hackers, due to the roblox protections put in place.

Top Articles
SPARKING Теги Piccolo & Son Goku
SPARKING Lebo ya Piccolo & Son Goku
Lilpeachbutt69 Stephanie Chavez
Ls 412 Blue Pill
Texas State Final Grades
Busted Paper Haysi Regional Jail
Walmart Academy Core Test Questions And Answers
Baldur’s Gate 3 difficulty settings and options
Project Zomboid Dynamic Skybox
Ciara Rose Scalia-Hirschman
Https://Cbdwarehousestore.com/Product-Category/Liquid-Herbal-Incense/
Central Mn Credit Union Perham
Azpeople Self Service
Pappadeaux Seafood Kitchen - Careers
Smithfield Okta Login
124 Indian Pointe, Unit 124, Osage Beach, MO 65065 | Compass
Study Restaurants Near Me
3D Billiards & 3D MiniGolf Bundle
Zelaya's Bakery Menu
Xk Class Scenario
Part City Near Me
CMFGUS33, SWIFT-Code für COMMUNITY FEDERAL SAVINGS BANK, NEW YORK
Byui Graduation Spring 2023
Yarzon Scavenger
Us 25 Yard Sale Map
Sparta Ymca
Chickasaw Garbage And Sewer
Feeling lucky? Top prizes still available for these Ohio Lottery scratch-off games
Davisk12
Wal-Mart 5220 Supercenter Photos
Encore Atlanta Cheer Competition
Joy Ride 2023 Showtimes Near Paragon Theaters - Coral Square
Joshua's Law Unit 7 Lesson 2
Gas Prices In Ottawa Il
Craigslist Free Stuff Chula Vista
Al Sandling Golf Carts
ORGANIC MORINGA SEED OIL
Matthew Berry’s 25 Most Interesting Things He Heard At 2024 NFL Combine
Us Open Tennis Sirius Radio
Obituary for GARY ALAN YOUNGS | After®
28 Box St
Unknown Venmo Charges on Bank Statement
Costco Gas Prices Sioux Falls
Depew Garbage Schedule 2023
Gluten Ease Walgreens
Stanford And Tate Furniture Blue Bloods
Koikatsu Card Booru
Teresa Palmer Fansite
Savage Funniest Texts Drunk
BEX Holiday Homes (Las Palmas de Gran Canaria): Alle Infos zum Hotel
Order Online (NOVI ONLY) | OSushi Restaurant
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6078

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.