Beginners Advanced Guide to Roblox

Become a Brick-smith in no time!

Scripting March 11, 2009

Filed under: Begginners Guide to advanced scripting — pokemonfan143 @ 12:09 pm
Tags: , , ,

 

What is scripting?

Scripting is a way to tell the computer what to do. However, computers can only understand commands if you tell them exactly what to do, in a specific code. ROBLOX Scripts are commands in a coding language called Lua. Lua is not-so-hard to understand, depending on the way you want to use it.

 

 

 

Being specific

Let’s make the most basic script: a suicide script. When it executes, it kills you. Scripting is just giving commands to the computer.

How do you kill a player? There are two ways to kill a character: disconnect their Head from their Torso, or have their Humanoid’s health dropped to zero. Don’t worry what a Humanoid is, we’ll use the first method for right now.

The game doesn’t know whom to kill, until you specify the username of the person whom you want to kill. Think of the structure of a ROBLOX game as a tree. The trunk is called “game”. Then there is a branch, called “Workspace”. Think of all the bricks as branches on that “Workspace” branch. (Bricks, by the way, are not stored by their position in the game. They are organized like leaves on the branches of this tree.) You are going to be a branch, called by your username, on the “Workspace” branch, on the “game” trunk.

Tree

 

 

 

 

 

 

 

Note that both the Players and the Workspace branch has a branch named after a specific user “jediknightkrazy”. That’s because there are two branches named after you, your player, and your character.

 

Translating to Lua

A script needs to be in a special coding language called Lua. This section will walk you through translating a basic English sentence to Lua code. Note: This is only to show you how to make a code from your english sentence. A Lua code does not change english into code, you must put Lua code for the computer to read.

 

Here’s our starting command:

I want to delete jediknightkrazy's head.

Naturally, ROBLOX won’t like that very much because it is in english. Remember the tree from the last section? First we have to tell ROBLOX where to find “jediknightkrazy”, and then his head.

In game, find Workspace, find jediknightkrazy, then find his Head.

In Lua, you go down the tree like this by using a dot: (.) This is required in every script that you wish to use a command line to find children or parents of objects.

delete game.Workspace.jediknightkrazy.Head

This is almost a working Lua statement. Now, to actually delete the head, a function must be used. To use this function, just type a colon (:) after the statement (in this case, after Head), and then the function you want to use, which in this case, is “Remove”. Then, put a pair of parentheses after the function name to tell the statement that you want this to be a function.

game.Workspace.jediknightkrazy.Head:Remove()

If your name isn’t jediknightkrazy, substitute your name for jediknightkrazy:

game.Workspace.YourName.Head:Remove()

To experiment a bit, try deleting the Torso instead

 

Testing the script

Open ROBLOX Studio and click File > New. Add a baseplate and a spawn.

To add a baseplate: Click Insert in the game window, NOT in the menu. Select “Free Models” in the drop down list at the right of the screen. Type “baseplate” and click Search. Add one that looks good.

To add a spawn: Select “Game Objects” in the drop-down list and click on a grey (neutral) spawn. + Now, in the menu, click Tools > Test > Visit Solo. This is where you can test your places without uploading them! + Once it loads, right click in the Toolbar and check Command if it isn’t checked already. A small textbox bar labelled “Command” should appear at bottom of the screen. In there, type:

game.Workspace.Player.Head:Remove()

Don’t replace Player with your username in Test mode, because your name is always “Player” in Test mode. Type it, don’t just copy and paste! Hit enter. If your head vanishes and you die, you’ve done it! You’ve made your first script. Now, try your Torso. Try removing the Baseplate; it’s called “Base”. 

 

Setting values and making objects

What about actually changing the value of an object, as opposed to removing an object? Earlier it was mentioned that there were two ways to kill someone. The more complicated way is setting one’s Health to 0. The Health is contained in a Humanoid object (Humanoid.Health), which is contained within the character (game.Workspace.Player).

Example:

game.Workspace.Player.Humanoid.Health

However, what about setting a value? In Lua, you set a value with the = sign. Put what you want to change; on the left. Then what you want to change it to; on the right:

game.Workspace.Player.Humanoid.Health = 0

Type it in the command bar like before, and you should be able to kill yourself without beheading yourself.

Note:in play solo from edit mode, your name is player not your username. Also, Workspace is a special object. Roblox was nice enough to let use use the phrase

workspace

rather than

game.Workspace

Workspace is the only special object that Roblox allows us to do this with.Example:

workspace.Player.Humanoid.Health = 0

 

4 Responses to “Scripting”

  1. not talkin Says:

    i still dont get it

  2. N/A Says:

    this is ripped off the wiki roblox,
    Absolute Beginner’s Guide To Roblox Scripting.

  3. U SUCK Says:

    THIS DOESNT WORK I TRY EVERY METHOD AND STILL DOESNT WORK TELL ME WHATS WRONG!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.