2 minute read

Scripting

Scripting is a very important skill to learn in Roblox Studio. It creates interactions and all mechanics behind the game, which changes how players interact in the game. In this section, you will learn the basics of scripting, and you will create some simple scripts with parts and UIs.

TL;DW (Too Long; Didn’t Watch)

Advertisement

Different Types of Scripts:

Scripts: Mainly for server scripts, largely used in ServerScriptService.

LocalScripts: Mainly for client scripts, largely used in StarterGui.

ModuleScripts (Not included in this tutorial): Mainly for functions, largely used in ServerScriptService.

Continue on next page...

Scripting Language:

Scripting language in Roblox Studio is called LuaU. It is very similar to Lua, which some Lua scripters will have a easier start.

Learning Scripts: Every time you create a script, you will see a default message stating: print(“Hello World!”). If you run a print command like this, you will see the statement shown in the server output.

For this tutorial, I will create a script which changes a part’s color and transparency, and a LocalScript which changes a TextLabel’s text.

Script that changes part’s color and transparency: Goal: Make the part half transparent and in orange.

1. Create a part in Workspace.

2. Create a script inside the part. This is called a children of the part.

3. Open the script and delete the default message.

4. Create a variable for the part. Type “local part = script. Parent” (without the quotes). This will create the variable that locate the parent of the script, which is the part.

5. Type “part.Transparency = 0.5” (without the quotes). This will make the part half transparent.

6. Type “part.Color = Color3.new()” (without the quotes). Inside the color3.new() brackets, select an orange color available in the color panel. This statement will make the part orange. Note that all statements in the scripts only work when playing in test mode or running the script using the tools in Test Tab. Continue on next page...

The script is finished. Now test the script using play mode or test mode!

If the part does not change its appearance, this shows your script contains some errors. To find out the errors, open the server output and read the error stated by the script.

The code for this script is stated below: local part = script.Parent part.Transparency = 0.5 part.Color = Color3.new(1, 0.533333, 0.0627451)

Please note that the numbers in the Color3.new bracket is only an example. There are many more numbers that create the orange colors.

LocalScript that changes TextLabel’s Text: Goal: Make the TextLabel showing “Hello!” when spawned in the game.

1. Create a ScreenGui in StarterGui.

2. Create a TextLabel inside the ScreenGui that you have just created.

3. Place the TextLabel into the center of the screen by dragging it around the workspace.

4. Create a LocalScript and delete the default message.

5. Create a variable for the TextLabel. Type “local label = script.Parent” (without the quotes). This will make the variable locating the TextLabel, which is the parent of the LocalScript.

Continue on next page...

6. Make a statement that changes the text of the label. Type “label.Text = “Hello!”” (without the first quotes, keep the quote for Hello!).

The LocalScript is finished. Test it out by playing the game in test mode. Do not use the test mode as UIs do not change in test mode!

If the TextLabel does not change its text on your side, this shows your LocalScript contains some errors. To find out the errors, open the server output and read the error stated by the LocalScript.

The code for this LocalScript is stated below: local label = script.Parent label.Text = “Hello!”

This article is from: