Deadly Lava
Part 1 - Getting Started
Deadly Lava
Part 1 - Getting Started

In Introduction to Coding, you learned how to make changes in a game in a loop over time. What if you want to make changes based on player behavior?

This course will show you how to make a deadly lava floor which kills a player when they step on it.

Setting Up

You’ll need a place in your game world to put the deadly lava. If you followed the Introduction to Coding 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 game world — call it LavaFloor.

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

  3. Make the floor look more like lava by setting the material to Neon and the color to orange.

  1. Insert a Script into the part and rename it to KillPlayer.

  2. Remove the default code and create a variable for the lava.

    local lava = script.Parent

Connecting to an Event

You’ll need to use an event to detect when a player touches the lava. Every part has a Touched event which fires when something touches it. You can connect to this event to run a function when it fires.

  1. Declare a new function called killPlayer.

  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 killPlayer()

Any code you write in the killPlayer 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 player, the function will need an object associated with that player. 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.

Function Parameters

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 killPlayer function.
local lava = script.Parent

local function killPlayer(otherPart)


When the killPlayer 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.

Next Page Killing the Player