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

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.

How long does it take to master Roblox scripting? ›

Roblox employs Lua, and learning the fundamentals of Lua can take anywhere from a few days to a few weeks, depending on how much time you devote to it. The more you practice, the more quickly you will learn.

What is the best scripting language for Roblox? ›

Roblox games and experiences are primarily written in Lua, a lightweight and versatile scripting language. Lua is widely used in game development due to its simplicity, flexibility, and ease of integration with various game engines and platforms.

Can u get banned for scripting in Roblox? ›

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.

Does Roblox use C++? ›

Yes, Roblox does also use C++ as well as Lua. When kids code with Roblox, they will be using Lua in the Roblox Studio, but some of the software used for memory management in the background has been developed with C++.

Can you learn Lua in a day? ›

Learning the basics of Lua can take anything from a few days to a few weeks, depending on the time you put into it. The more you practice, the faster you will learn.

How much script activity is bad Roblox? ›

The best thing to look at is user reports and playtesting. Roblox could do a lot better about telling you how your game's performance measures up. That being said, I've also read that anything above 3% activity is considered bad and that you shouldn't really worry about the rate.

How long does it take for 1000 Robux to come through? ›

Usually, it takes about 3-7 days for 1000 robux to pend, but sometimes it can be quicker or take up to 30 days based on the transaction type and your account status. Anywhere from 3-7 days, but occasionally it might stretch to 30 days. Roblox can be unpredictable!

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.

What code is Roblox scripting? ›

Roblox scripts use the Luau programming language, which is derived from Lua 5.1. Compared to Lua 5.1, Luau adds performance enhancements and many useful features, including an optional typing system, string interpolation, and generalized iteration for tables.

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.

Does Roblox have AI chat? ›

Roblox built an AI model that it says translates text chats so quickly users may not even notice it's translating the messages of other players at first. It works with 16 languages, including English, French, Japanese, Thai, Polish, and Vietnamese.

Is Roblox scripting Python? ›

Roblox uses Lua. There are few syntaxes where are similar in both Python and Lua.

Is scripting harder than coding? ›

Scripting languages are often simpler than standard programming languages, which makes them less difficult for novices to learn. Scripts are often brief and use simple syntax, and they frequently conceal features such as data storage and memory usage from the end-user.

Is it hard to learn scripting? ›

Learning a scripting language is an excellent introduction to coding and programming. They are relatively easy to learn and can be an effective jumping-off point to pursue your hobbies or career interests further.

Is coding on Roblox easy? ›

It is known for its simplicity and ease of use, making it a popular choice for beginners and experienced programmers alike.

Is Roblox code hard to learn? ›

Roblox coding is fairly hard for beginners. Most kids and teens have likely not interacted with complex coding environments like Roblox Studio before, which has two big aspects to it: building and scripting.

Top Articles
Georgia Scratch Offs Remaining
Craigslist Pets Syracuse Ny
Tripper Bus Promo Code
Ozark Funeral Home | Anderson, Missouri
K-Active – Jetzt kaufen bei SVG
Market Place Traverse City
Craigslist Tn Free Stuff
Onlinewagestatements Lifepoint
Craigslist Ft Meyers
Funny Spotify Playlist Covers 300X300
Bj타리
Don Misael Tamales Menu
7Soap2Day
Safety Jackpot Login
Hingham Police Scanner Wicked Local
Pdq Menu Nutrition Facts
Conceitos Básicos de Informática - Informática
Kaiser Northgate Pharmacy Hours
Lorain County Busted Mugshots
Goodwill Fairport
BERNZOMATIC TS4000 INSTRUCTION MANUAL Pdf Download
Green Light Auto Sales Dallas Photos
Android için OGWhatsApp Apk v19.41.1'i İndirin (En Son)
Wendy Moniz Swimsuit
Craigslist Hunting Land For Lease In Ga
Zuercher Portal Inmates Clinton Iowa
Us 25 Yard Sale Map
Dashmart Bloomington
Craigslist General Labor Annapolis
Move Relearner Infinite Fusion
Exzellente Überseelogistik „Made in Austria“
Dit zijn de 14 beste restaurants van Amsterdam
Apolonia's Prime Steakhouse Okeechobee Fl
Retiree Aon Com Att Login
Petsmart Donations Request
Uncovering The Mystery Behind Crazyjamjam Fanfix Leaked
Milwaukee Nickname Crossword Clue
Sean Hannity My Pillow Promo Code 2022
Kamado Joe 457 Manual
Cheap Car Rentals in Mexico from just $5 | momondo
Craigslist Columbus Oh
Tomorrow Tithi In Usa
How To Add Friends On Regal App
28 Box St
Ukg.adventhealth
Mychart Kki
Aeries Birmingham Portal
Federal Express Drop Off Center Near Me
Arizona Cardinals 5050
Rcs Carnival Laveen Az
Find your Routing Number (ABA) Transit Number - Wise
The Emergent Care Clinic Hesi Case Study
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 6076

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.