Deadly Lava | Documentation - Roblox Creator Hub (2024)

In Introduction to Scripting, you learned how to make changes in an experience in a loop over time. What if you want to make changes based on user behavior? In this tutorial, you'll learn how to make a deadly lava floor which kills users when they step on it.

Setting Up

You need a place in your world to put the deadly lava. If you followed the Introduction to Scripting course, the lava floor would fit nicely in the gap covered by the disappearing platforms.

  1. Insert a Part and move it into place in your world. Name it LavaFloor.

  2. Resize it so it covers the floor of the enclosing space.

    Deadly Lava | Documentation - Roblox Creator Hub (1)

  3. Make the floor look more like lava by setting the Material property to Neon and the Color to an orange shade.

    Deadly Lava | Documentation - Roblox Creator Hub (2)
    Deadly Lava | Documentation - Roblox Creator Hub (3)
  4. Insert a Script into the LavaFloor part and rename it to Kill.

    Deadly Lava | Documentation - Roblox Creator Hub (4)
  5. Remove the default code and create a variable for the lava.

    local lava = script.Parent

Connecting to an Event

Use an event to detect when a user touches the lava. Every part has a Touched event that fires when something touches it. You can connect to this event to run a function when it fires.

  1. Declare a new function called kill.

  2. Access the Touched event on the lava object using a dot, just like a property: lava.Touched.

  3. Call the Connect function on the Touched event, passing the kill function.

    local lava = script.Parent

    local function kill()

    end

    lava.Touched:Connect(kill)

Any code you write in the kill function will now run whenever something touches the lava. Note that a colon is used for the Connect function, not a dot - don't worry about why at this point, just remember the difference.

Getting the Touching Part

To kill the user, the function will need an object associated with that user. A part's Touched event can provide the "other part" that touched it — but only if you request it by making it a parameter of the function.

Parameters are definitions of what a function expects to receive when it's called. A parameter can be used in a function just like any other variable. You can pass information to a parameter by including it in the parentheses when a function is called. Parameters are defined in the parentheses on the first line of a function. Create a parameter called otherPart for the kill function.

local lava = script.Parent

local function kill(otherPart)

end

lava.Touched:Connect(kill)

When the kill function is called, the otherPart parameter will represent the part that touched the lava floor, and the code you'll write in the function will be able to use it.

Character and Humanoid

When a user touches the lava, Roblox can detect the specific body part of the user that touched it, such as the left leg or right foot. This part is in the user's Character model, which contains all of the objects that make up the user's avatar in the experience, including:

  • The individual body parts of the user such as the head, limbs, and torso.

  • Any clothing and accessories worn by the user.

  • The Humanoid, a special object which contains many properties related to the user, including the user's health.

  • The HumanoidRootPart which controls the user's movement.

As previously noted, any body part that touches the lava is part of the Character model, so you can get a reference to that character with otherPart.Parent. Create a variable to store the parent of the part that touched the lava floor.

local lava = script.Parent

local function kill(otherPart)

local partParent = otherPart.Parent

end

lava.Touched:Connect(kill)

From the character model, you'll need to get the Humanoid object in order to kill the user. You can do this with the FindFirstChild() function—just pass it the name of the thing you're looking for and it provides the first matching child it finds in that object. Call FindFirstChild() on the partParent variable with "Humanoid" as the child to find, and store the result in a new variable called humanoid.

local lava = script.Parent

local function kill(otherPart)

local partParent = otherPart.Parent

local humanoid = partParent:FindFirstChild("Humanoid")

end

lava.Touched:Connect(kill)

Checking the Humanoid

You can easily check if the Humanoid was found using an if statement. The code in an if statement will only run if the condition defined in the first line is true.

There are a variety of operators that can be used to build more complex conditions which you'll encounter in future courses - for now, just put the humanoid variable there. Create an if statement with humanoid as the condition.

local lava = script.Parent

local function kill(otherPart)

local partParent = otherPart.Parent

local humanoid = partParent:FindFirstChild("Humanoid")

if humanoid then

end

end

lava.Touched:Connect(kill)

In Lua, any value other than false or nil (an empty value) is evaluated as true in a conditional statement, so in this case you can use humanoid directly as the condition.

Setting Character Health

Now that the Humanoid has been checked, its properties can be changed. If you set its Health property to 0, the associated Character dies. In the body of the if statement, set the Health property of humanoid to 0.

local function kill(otherPart)

local partParent = otherPart.Parent

local humanoid = partParent:FindFirstChild("Humanoid")

if humanoid then

humanoid.Health = 0

end

end

lava.Touched:Connect(kill)

With that, your lava floor is complete! Test your experience and you should find that your deadly lava successfully kills users on contact. Try using your lava as an extra challenge in an obby, or as a boundary for a world.

Final Code

local lava = script.Parent

local function kill(otherPart)

local partParent = otherPart.Parent

local humanoid = partParent:FindFirstChild("Humanoid")

if humanoid then

humanoid.Health = 0

end

end

lava.Touched:Connect(kill)

Deadly Lava | Documentation - Roblox Creator Hub (2024)
Top Articles
Zuletzt gesehen am Zoll | Tarkov Schlägerverfolger
Escape From Tarkov Stray Dogs: How To Kill The Goon Squad
Supermotocross Points Standings
Maricopa County Property Assessor Search
Lamb Funeral Home Obituaries Columbus Ga
Miller Motte College Student Portal
Tmobile Ipad 10Th Gen
19 Dollar Fortnite Card Copypasta
Selinas Gold Full Movie Netflix
Northamptonshire | England, Map, History, & Facts
Midlands Tech Beltline Campus Bookstore
Great Clips Coupons → 20% Off | Sep 2024
Cappacuolo Pronunciation
159 Joseph St, East Brunswick Township, NJ 08816 - MLS 2503534R - Coldwell Banker
Gas Station Drive Thru Car Wash Near Me
Descargar AI Video Editor - Size Reducer para PC - LDPlayer
What To Do With Mysterious Camera In Sakura Stand
Uc My Bearcat Network
Craigslist Folding Table
Ninaisboring
Google Flights Msp To Fort Myers
Wdef Schedule
Biobased Circular Business Platform
Restored Republic August 10 2023
Scythe Banned Combos
Horned Stone Skull Cozy Grove
Premium Car Rental in Vancouver
Webmail.unt.edu
Dom's Westgate Pizza Photos
Nebraska volleyball's Harper Murray trying to regain trust, recapture love
Rimworld Prison Break
Flixtor The Meg
Craigslist/Lakeland
Arsenal’s Auston Trusty: Inspired by Ronaldinho, World Cup dreams and Birmingham loan
Tires Shop Santoyo
Santa Cruz Craigslist Cars And Trucks - By Owner
Pokemon Infinite Fusion Download: Updated | PokemonCoders
Directions To Truist Bank Near Me
Retro Bowl Unblocked Game 911: A Complete Guide - Unigamesity
Re/Max Houses For Sale
Tamusso
Bob Wright Yukon Accident
South Dakota Bhr
Feetfinder Reviews Trustpilot
Lost Pizza Nutrition
How to Set Up Dual Carburetor Linkage (with Images)
Locate Td Bank Near Me
Desi Cinemas.com
Equine Trail Sports
Wis International Intranet
Stpeach Forum
26200 E 64Th Ave
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5662

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.