How to Script A Kill Brick in Roblox

In this article, I’ll teach you how to script a kill brick in Roblox from scratch.

What is a Kill Brick?

Kill bricks are types of parts in Roblox that will kill any player that touches them.

How to Make a Kill Brick in Roblox Studio?

If you want to learn how to script a kill brick in Roblox from scratch, there are a few prerequisites. Don’t worry, they’re easy prerequisites!

First, you’ll want to make sure that you have Roblox Studio downloaded. If you need any help accessing Roblox Studio, please read this article.

From there, you’ll want to make sure that you can view the Explorer window, and that you can also view the Properties window

The baseplate template in Roblox Studio.

At this point, you should be looking at the baseplate and spawn location.

I would recommend you remove the SpawnLocation, as it can cause problems when following this tutorial.

To do so, click on the SpawnLocation in the Explorer and press your delete key on your keyboard.

And poof! The SpawnLocation should be gone.

Building the Kill Brick

Before we can script a kill brick in Roblox, we need to build the actual brick that will kill players when they touch them.

Start by clicking on the (+) button next to the Workspace and searching for “Part”

Now, you should see a Part in Workspace.

Changing the Kill Brick’s Properties

Right now, our kill brick looks like a plain old gray brick.

Let’s give it some stylish looks!

BrickColor

A lot of games use the color red to denote that the brick will kill you.

You can set the color of the kill brick to red by going into the Properties window and setting the BrickColor to red.

To do so, click on your Part in the Explorer.

Then, click on that “Medium stone grey” property next to BrickColor, which should open up the BrickColor palette window.

The BrickColor palette window allows you to choose different colors for your Part.

After selecting the red color, your Part should be red!

After changing the Part’s BrickColor, it’s red.

Neon Material

We can make this Part look even more killer if it’s glowing like a laser.

Set the Part’s Material to Neon using the Properties window.

Change the Material to Neon

And you should see our beautiful glowing part.

Our Part now glows
Our Part now appears to glow, radiating energy

Size

Awesome! All that’s left for the building of our Part is making it a bit bigger.

You can use Roblox’s built-in scale tool to make the Part bigger.

Click on your Part, and click on the Scale button on the ribbon bar on the top of Roblox Studio.

The Roblox Scale tool allows you to resize your part
The Scale Tool allows you to resize your Part

I have dragged the red handles outward, making the Part longer.

The kill brick is now longer
The Kill Brick is now longer

Scripting the Kill Brick

All that’s left is making the kill brick, well, kill any player that touches it.

Now, I’ll teach you how to script a kill brick in Roblox.

For this, we’ll need to use a Script.

If you’re completely new to scripting, it might be helpful to view this easy tutorial for beginner scripters first.

We’ll start by adding a Script object into the kill brick.

To do this, click on the Part in the Explorer and add a Script to it, in the same way that we added a Part before.

Roblox’s default Script contents

Now, you should be looking at a:

We can get rid of it, as we’ll be scripting our own kill brick from scratch.

The Touched Event

For our kill brick, we want it to do something when something touches it.

In order to set it up so that it does stuff when something touches it, we need to use a Touched event.

A Touched event basically tells Roblox “I want this object to do something when it is touched by another object.”

So, we start here:

In that piece of code, the part is referring to our kill brick.

Then, the part.Touched stuff is us telling Roblox “I want something to happen when this part gets touched by something else.”

And after the part gets touched, it will print whatever touched it (as I have denoted with a parameter called hit) on the Output.

Our code now prints whatever object touches our Part

You can test this code by pressing F5 on your keyboard, or the blue play button.

You can view the Output window by clicking the second button on the grid

Now, if you can’t see your Output, click “VIEW” on the top, and click on the second of the tiny buttons.

And on your Output, you should see that our Script has detected that the Baseplate (the giant gray checkered thing) has touched the kill brick.

Our script is able to successfully detect the objects that touch the kill brick

And if we walk over to the kill brick, it will print the stuff inside our character.

As you can see, our script is detecting all sorts of stuff, like:

  • Our RightLowerLeg
  • Our RightFoot
  • Our HumanoidRootPart
  • The Baseplate

The script is actually detecting the different body parts that are inside of our Roblox character that have touched the object, as well as the Baseplate.

In our code, the word hit refers to the object that has touched it.

Now, we need to tell Roblox “detect only if the object that touched it is part of a player.”

In other words, we have to perform some hit validation.

Hit Validation

Our current code will print whatever object touched the kill brick.

With a few changes, we can get it to detect only the objects that have health (like players).

In here, we are using something known as if statements to make sure that the object that touches our kill brick has a Humanoid.

The reason we need to make sure that it has a Humanoid is because every Player’s Character has a Humanoid object, and Humanoids have a Health.

We can test our new code by pressing F5 or the blue play button.

The Output now shows the different objects that are touched by our character.

And you can see that the Output never shows the Baseplate.

That’s because it’s only detecting objects with a Humanoid, and Baseplates don’t have Humanoids.

Players’ Characters, however do.

Killing the Player

The last step is to kill the player that touched the part.

By setting their Humanoid.Health to 0, the player that touched it will die.

Here:

  • hit is the object that touched the kill brick (like my RightFoot, my RightLower Leg)
  • part is our Kill Brick
  • hit.Parent is the character
  • hit.Parent.Humanoid is the Humanoid that exists inside of the character
  • hit.Parent.Humanoid.Health = 0 is us telling Roblox to set the Health of the Humanoid to 0.

Try out your game!

Our new Roblox kill brick behaves as expected.
Our kill brick works as expected

What’s Next?

Great job following along with the tutorial on how to script a kill brick in Roblox!

🚀 Want to learn more Roblox scripting?

My book takes you step by step, from knowing nothing to being able to write your own scripts.

👉 Grab your copy here

The next article that you may be interested in is turning this kill brick into a full obby.

Or maybe you want to learn how I got started learning Roblox scripting, which you can read by clicking here.

kushal Avatar

About the author

Subscribe to Kushal Writes

Awesome tips for game development, computer science, and life lessons to help you succeed — straight to your email for FREE!

Join 50+ readers

    By submitting this form, you’ll be signed up to my free newsletter. You can unsubscribe at any time.

    Learn Roblox Scripting

    Get the Beginner’s Guide to Roblox Scripting Book and learn Roblox scripting in an easy to understand way.



    Search Kushal Writes