How to Script on Roblox for Beginners

Learn How to Script on Roblox for Beginners? Roblox is a user generated online gaming platform that was created by Roblox Corporation in 2006 and went viral soon afterwards.

This game allows players the ability to create and design their own virtual simulations.

learn to script on roblox

Roblox also has an in game currency (Robux) which can be rewarded to users and developers which in turn can be changed to cash the developer exchange program.

The game is designed in a way that players are able to discover 3-D worlds. Activities in the game include exploring, crafting items, resource gathering and combat.

It also boosts social interaction , because players have the ability to add other people they meet in the game to their friends’ lists.

An example of such popular games is Roblox Dinosaur Simulator in which the gamer can live as one of the most majestic, prehistoric and amazing creature to have ever lived: The Dinosaur.

What is Roblox Scripting?

A script is a set of instructions for a program to follow in order to create custom behaviors and in order to give these instructions you must give the instructions in a language in which the program can properly interpret and understand

PRINT

The first instruction, or function, we will cover is called print, which makes text appear in the Output window. In the Command Bar, type:

print(“Hello world!”)

After you are done typing, hit enter. The Output panel will show both the instruction and the message we wanted to print:

> print(“Hello world!”)

Hello world!

print will output whatever is in between the parenthesis () that follow it. In this case, we printed out the sentence: Hello world!. When you want to print out sentences, which in Lua are called strings, you have to surround the sentence with quotations.

We can print other things, like numbers:

> print(10)

10

Please note that these commands are case sensitive, and so you must endeavor to spell the print exactly as you see above with all lower case letters. For instance “Run” is very much different from “run” or “RUN”.

Programs are extremely specific and precise on how commands are spelt and capitalized. If you do something as minor as mis capitalizing a command, you will see an error in the output window.

Check Also: Best Roblox Jailbreak Hack

How to Script on Roblox for Beginners?

Sometimes,  in scripting, we might wish to store a particular information that we would use at a point in time in the future. This is when variables come into play.

Just think of a variable as a box in which you put things that you’ll need later.

To create a variable, you will simply need to name it and assign a particular value to it. For example

>myAge = 27   This is a variable.

The example above will store the number 27 into the variable called myAge.

First we are specifying the name of the variable we wish to use, in this case myAge.

The equal sign says we wish to assign a number to that specific variable. The value we need to store comes after the equals sign.

Make sure to read: How to Change Your Name in Roblox?

VARIABLE NAMES

We can assign variables to almost any name we desire, however there are a few laid down rules that one must follow in Lua when naming variables:

  • Variable names cannot have spaces in them.
  • Variable names cannot start with numbers.
  • Variable names cannot have any special character except for underscore: _.
  • Some words in Lua are reserved for special uses. Variable names cannot be the same as these special words. A few examples are for, and, end, if, and while.
  • Variable names should not be the same as functions. For example, you technically can use the word print as a variable name, but it would ruin your program as that would overwrite the actual print function.

BASIC MATCH

You will often be required to do a bit of math during scripting. Lua supports all the basic mathematical operations.

CREATING A NEW PART

You can create a new part via code. To do this, simply type the following command:

The command will automatically insert new parts into the workspace. This part will show up in both the 3D view and the explorer.

You can also store parts inside variables.

> Instance.new(“Part”, Workspace)

You should also read: Roblox Twisted Murderer Codes and Hack

CHANGING PROPERTIES

Any properties that you can set with studio tools or through properties window can be changed or modified with a script command.

In order to change a property of something you have initially stored in a variable, you have to provide the variable, the property you wish to change and the value you want to property to be changed to.

In coding, this must be presented in a very precise and specific pattern.

Look at the example below.

> myPart.Name = “Bob”

You can change other properties as well. For instance if you want to make a part slightly transparent, you can adjust the transparency property.

> myPart.Transparency = 0.5

 

A roblox game is structured in what is called a tree. The game itself actually resides at the top of the tree. It is referred to in code as Game”

Beneath the game are standard services like workspace, players, lighting, etc. These are termed “Children”  Likewise, Game is considered as “Parent”

The workspace itself has several children of its own: Terrain, camera, baseplate

Now that you are familiar with the structure and organization , we can talk about how to access an object in the explorer through code.

When we want to get to a specific object, we have to write how to get there via the tree. For example, suppose we want to change the Transparency of the Baseplate. We know the Baseplate is a child of Workspace, which itself is a child of game. To access an object in code, we start at the highest level and then work down through the children. So, we start at game as that is the highest level in the tree.

game

To move to a child, we have to write dot (.) then the name of the child. In this case, we want to move to Workspace so we would write:

game.Workspace

We can descend another level to the Baseplate by writing another dot (.) and then Baseplate:

game.Workspace.Baseplate

Now that we are at the Part we are interested in, we can access the Property we are interested (with a dot, just like above), and then set it.

> game.Workspace.Baseplate.Transparency = 1

The Name property of parts is critical when running code like above. To access parts like above the Name has to be spelled correctly. The Name also cannot include any spaces. If the part was named Base plate the above code would not work.

It is also important to give your parts unique names if they are in the same service or folder. If there were two parts named Baseplate and you tried to change the transparency of one using the above code, the game would pick one of the parts and there is no guarantee that it would pick the part you want. A better approach would be to name parts like Baseplate1 and Baseplate2 if you need to change them individually from code.

Hope you got answer for how to Script on Roblox for Beginners? Please share your own thoughts here.

Leave a Reply

Your email address will not be published. Required fields are marked *