Introduction to Scripting | Documentation - Roblox Creator Hub (2024)

In Introduction to Roblox Studio, you learned how to create and manipulate parts in Roblox Studio. In this tutorial, you'll learn how to apply a script to parts to make a platform appear and disappear. You can use this in a platforming experience to span a gap, challenging users to time their jumps carefully to get to the other side.

Setting the Scene

First off, you need a Part to act as the platform. Making and moving parts should be familiar to you from Introduction to Roblox Studio. You don't need a complicated world aside from the platform — you just need a gap that your users can't easily jump across.

  1. Insert a Part and rename it to DisappearingPlatform.

  2. Resize it to large enough for a user to jump on.

  3. Move it to a proper location so that you can reach it and jump on it when testing your experience.

    Introduction to Scripting | Documentation - Roblox Creator Hub (1)

  4. Set the Anchored property to true in the Properties window.

    Introduction to Scripting | Documentation - Roblox Creator Hub (2)

Remember that setting a part's Anchored property to true makes it stay in place no matter what. Your platform falls down if it's not anchored.

Inserting a Script

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.

  1. Hover over the DisappearingPlatform part in the Explorer window and click the + button to insert a new script into the platform. Rename your new script as Disappear.

    Introduction to Scripting | Documentation - Roblox Creator Hub (3)
  2. Delete the default code inside.

Remember to rename parts and scripts as soon as you create them so you don't lose track of things in the Explorer.

First Variable

It's a good idea to start off your script by making a variable for the platform. A variable is a name associated with a value. Once a variable is created, it can be used again and again. You can change the value as needed.

In Luau, a variable is created as follows: local variableName = variableValue.

The term local means that the variable is only going to be used in the block of the script where it's declared. The = sign is used to set the value of the variable. Names for variables are typically written in camel case. This is lowercase with every word following the first being capitalized, justLikeThis.

Copy the following code to create a variable for the platform called platform, where the value is script.Parent.

local platform = script.Parent

script.Parent is used to find the object the script is located in. As you might have guessed, script refers to the script you're writing in and the Parent of the script is where it's located.

Disappear Function

Time to make the platform disappear. It's always best to group code for achieving a specific action into a function. A function is a named block of code that helps you organize your code and use it in multiple places without writing it again. Create a function in the script and call it disappear.

The first new line declares the function — it indicates the start of the function and names it as disappear. The code for a function goes between the first line and end.

The parentheses are for including additional information as needed. You'll learn more about passing information to functions in a later course.

Part Properties

When the platform disappears, it needs to be invisible and users need to fall through it — but you can't just destroy the platform since it needs to reappear later.

Parts have various properties that can be used here. Remember that you can see a part's properties if you select it and look at the Properties window.

A part can be made invisible by changing the Transparency property. Transparency can be a value between 0 and 1, where 1 is fully transparent and therefore invisible.

The CanCollide property determines if other parts (and users) can pass right through the part. If you set it to false, users will fall through the platform.

Just like script.Parent, properties are accessed using a dot. Values are assigned using an equals sign.

  1. In the disappear function, set the CanCollide property of the platform to false.

  2. On the line following, set the Transparency property to 1.

    local platform = script.Parent

    local function disappear()

    platform.CanCollide = false

    platform.Transparency = 1

    end

You might notice that Studio automatically indents your code inside a function. Always make sure to indent your code like this — it helps indicate where the function begins and ends, which makes your code more readable.

Calling the Function

Once you've declared a function, you can run it by writing its name with parentheses next to it. For example, disappear() will run the disappear function. This is known as calling a function.

  1. Call the disappear function at the end of the script.

    local platform = script.Parent

    local function disappear()

    platform.CanCollide = false

    platform.Transparency = 1

    end

    disappear()

  2. Test the code by pressing the Play button. If your code works, the platform should have disappeared by the time the user spawns into the game.

Appear Function

You can easily make the platform reappear by writing a function that does the exact opposite of the disappear function.

  1. Delete the disappear() line from the script.

  2. Declare a new function called appear.

  3. In the function body, set the CanCollide property to true and the Transparency property to 0.

    local platform = script.Parent

    local function disappear()

    platform.CanCollide = false

    platform.Transparency = 1

    end

    local function appear()

    platform.CanCollide = true

    platform.Transparency = 0

    end

Looping Code

The platform should be constantly disappearing and reappearing, with a few seconds between each change. It's impossible to write an infinite number of function calls — fortunately, with a while loop, you don't have to.

A while loop runs the code inside it for as long as the statement after while remains true. This particular loop needs to run forever, so the statement should just be true. Create a while true loop at the end of your script.

local platform = script.Parent

local function disappear()

platform.CanCollide = false

platform.Transparency = 1

end

local function appear()

platform.CanCollide = true

platform.Transparency = 0

end

while true do

end

Toggling the Platform

In the while loop, you need to write code to wait a few seconds between the platform disappearing and reappearing.

The built-in function task.wait() can be used for this. In the parentheses the number of seconds to wait is needed: for example task.wait(3).

Whatever you do, never make a while true loop without including a task.wait() — and don't test your code before you've put one in! If you don't wait, your game will freeze because Studio will never have a chance to leave the loop and do anything else.

Three seconds is a sensible starting point for the length of time between each platform state.

  1. In the while loop, call the task.wait() function with 3 in the parentheses.

  2. Call the disappear function.

  3. Call the task.wait() function again with 3 in the parentheses.

  4. Call the appear function.

while true do

task.wait(3)

disappear()

task.wait(3)

appear()

end

The code for the platform is now complete! Test your code now and you should find that the platform disappears after three seconds and reappears three seconds later in a loop.

You could duplicate this platform to cover a wider gap, but you need to change the wait times in each script. Otherwise, the platforms will all disappear at the same time and users will never be able to cross.

Final Code

local platform = script.Parent

local function disappear()

platform.CanCollide = false

platform.Transparency = 1

end

local function appear()

platform.CanCollide = true

platform.Transparency = 0

end

while true do

task.wait(3)

disappear()

task.wait(3)

appear()

end

Introduction to Scripting | Documentation - Roblox Creator Hub (2024)

FAQs

What does == mean in Roblox? ›

Comparison Operators

== : Is equal to. ~= : Is not equal to. < or > are used for less or greater than, respectively. <= or >= are used for less/greater than or equal to, respectively.

Does Roblox use C++? ›

Roblox games and the Roblox platform itself are primarily built and scripted using Lua and C++.

Is Roblox scripting easy to learn? ›

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 does UwU mean on Roblox? ›

uwu is an emoticon depicting cuteness, used to express various warm, happy, or affectionate feelings ☺️ UwU. dj_delish. 164.

What does ABC for a girl mean in Roblox? ›

ABC – This doesn't stand for anything. ABC means asking another player (or telling another player you're ready) to make an offer, trade or perform a task in Roblox, such as roleplaying in a game. AFK – Away from keyboard. Players say this when taking a break from the game for a while.

Is scripting legal in Roblox? ›

Is scripting allowed in Roblox? Scripting is definitely allowed in Roblox and Roblox scripts can in fact do a wide variety of creative things. Almost all games in Roblox use scripts to make them more dynamic and fun. Roblox scripting is done in the Roblox Studio editor and uses a programming language called “Lua”.

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 Lua hard to learn? ›

Absolutely not. Whilst every programming language has it's variations and tricky parts, Lua is one of the easier languages for a kid to learn.

Is Lua easier than Python? ›

Lua and Python are both interpreted, dynamically typed, garbage-collected programming languages. Lua is smaller than Python, making it easier to learn and embed. However, Python is better supported and more widely applicable.

Is Roblox C sharp? ›

C# and Luau

For scripting, Unity uses C#. Roblox uses Luau, a scripting language derived from Lua 5.1. Compared to C#, Luau is gradually typed and generally has a less verbose syntax.

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.

What is the hardest coding script to learn? ›

Most esoteric programming languages like Malbolge, Cow, Whitespace, etc. are considered the hardest coding languages to learn with close to no applications or advantages.

Is Roblox coding hard? ›

If you work hard you can possibly form a decent understanding of roblox's engine and lua in a month, but thats not very realistic. The project i described above took me months of hard work to get working.

What does == mean in code? ›

Equality operators: == and !=

The result type for these operators is bool . The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false .

What does == mean in Lua? ›

The operator == tests for equality; the operator ~= is the negation of equality. We can apply both operators to any two values. If the values have different types, Lua considers them different values.

What is duplicate in Roblox? ›

As you build, parts can be used more than once by creating duplicates. This is useful for reusing a part from the scrapyard, or copying something already added to the speeder. Click the wing you just added and duplicate it (Ctrl+D or ⌘+D).

What does ~= do in Roblox? ›

Relational
OperatorDescriptionExample
~=Not equal to3 ~= 5 → true
>Greater than3 > 5 → false
<Less than3 < 5 → true
>=Greater than or equal to3 >= 5 → false
2 more rows

Top Articles
How small changes will help Mercedes avoid more ‘magic button’ trouble
The changes that will help Mercedes avoid more 'magic button' trouble
Bleak Faith: Forsaken – im Test (PS5)
Nehemiah 4:1–23
Jonathon Kinchen Net Worth
DEA closing 2 offices in China even as the agency struggles to stem flow of fentanyl chemicals
Gore Videos Uncensored
Optum Medicare Support
Minn Kota Paws
13 The Musical Common Sense Media
Obituary Times Herald Record
Tight Tiny Teen Scouts 5
Items/Tm/Hm cheats for Pokemon FireRed on GBA
83600 Block Of 11Th Street East Palmdale Ca
5808 W 110Th St Overland Park Ks 66211 Directions
Jack Daniels Pop Tarts
Five Day National Weather Forecast
Lancasterfire Live Incidents
Honda cb750 cbx z1 Kawasaki kz900 h2 kz 900 Harley Davidson BMW Indian - wanted - by dealer - sale - craigslist
Candy Land Santa Ana
Copart Atlanta South Ga
Allybearloves
Tu Pulga Online Utah
Ppm Claims Amynta
The best brunch spots in Berlin
JVID Rina sauce set1
13301 South Orange Blossom Trail
27 Fantastic Things to do in Lynchburg, Virginia - Happy To Be Virginia
Stickley Furniture
Select The Best Reagents For The Reaction Below.
Our Leadership
Craigslist Scottsdale Arizona Cars
First Light Tomorrow Morning
Pnc Bank Routing Number Cincinnati
What Time Is First Light Tomorrow Morning
Back to the Future Part III | Rotten Tomatoes
Omnistorm Necro Diablo 4
Zero Sievert Coop
Quake Awakening Fragments
Academic important dates - University of Victoria
Los Garroberros Menu
craigslist | michigan
Mid America Irish Dance Voy
Download Diablo 2 From Blizzard
Three V Plymouth
Trivago Anaheim California
ACTUALIZACIÓN #8.1.0 DE BATTLEFIELD 2042
Elven Steel Ore Sun Haven
3500 Orchard Place
Ty Glass Sentenced
Sml Wikia
Tommy Gold Lpsg
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 5443

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.