Tutorial on how to make a kill brick

Hello and good morning guys!

Today I’m gonna show you how to make a kill brick for your Roblox game. Let’s get started

To create a Kill Brick in Roblox using Luau I have created a script to help you with this task.

` local part = script.Parent

local function onTouch(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChild(“Humanoid”)

if humanoid then
    humanoid.Health = 0  -- Instantly kills the player
    -- Alternative: humanoid:TakeDamage(100)  -- Does 100 damage
end

end

part.Touched:Connect(onTouch) `

  1. Insert a part into your game (this will be your kill brick)
  2. Insert a Script into the part
  3. Paste the code above into the script

Variations:

  1. With respawn effect:

` local part = script.Parent

local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.Health = 0
– Optional visual effects:
part.BrickColor = BrickColor.new(“Really red”)
local explosion = Instance.new(“Explosion”)
explosion.Position = part.Position
explosion.Parent = workspace
end
end
part.Touched:Connect(onTouch) ```

I hoped you enjoy this tutorial have a great day and a great kill brick!

4 Likes

I mean this is nice for beginners, but how would they learn? They don’t understand the material they are using? Add a description for what each line does, and please format your post with proper code blocks using the ` 3 times usually.

4 Likes

This script is only well optimized for a single kill brick, for multiple kill bricks - which you will probably be using - use the CollectionService with tags. You only need one script with this approach. Also, adding a debounce will allow you to take damage slower. I also added some comments to help show what each part does.

local CollectionService = game:GetService("CollectionService")
local TAG = "KillBrick" -- A unique tag
local KILL_BRICK_DAMAGE = 25 -- Damage per second

-- Listen for .Touched on a new killBrick
local function NewKillBrick(killBrick)
	local debounce = false -- Prevents player from touching part constantly
	
	killBrick.Touched:Connect(function(touchedPart: BasePart) -- Part was touched		
		local character = touchedPart.Parent
		local humanoid = character:FindFirstChild("Humanoid")
		
		if humanoid then
			if debounce then return end -- Don't continue if debounce == true
			debounce = true -- Don't allow player to touch part for now
			
			humanoid:TakeDamage(KILL_BRICK_DAMAGE)

			task.wait(1) -- Wait before allowing player to touch part
			debounce = false
		end
	end)
end

local initiallyTagged = CollectionService:GetTagged(TAG) -- Get kill bricks

for _, killBrick in initiallyTagged do -- Loop through kill bricks
	NewKillBrick(killBrick)
end

CollectionService:GetInstanceAddedSignal(TAG):Connect(function(killBrick) -- New kill brick added
	NewKillBrick(killBrick)
end)

For this method:

  1. Create a script with this code; it’s probably going to have errors so have fun debugging (it’s good experience)
  2. Create a kill brick and add the tag specified in the script (here it’s “KillBrick”)
3 Likes

I’m not sure about Maybe something getting game error Console check need you have problem

1 Like

Yeah, I just quickly wrote out the script on the devforum so I have no idea if this works. I’ll check in studio now.


Just tested and this works for me.

1 Like

You need have idea Something used script wrong not working on Run trying error

1 Like

-- Place this script inside the Kill Brick part

local killBrick = script.Parent

killBrick.Touched:Connect(function(hit)
    local character = hit.Parent
    local humanoid = character:FindFirstChild("Humanoid")

    if humanoid then
        humanoid.Health = 0 -- Kills the player
    end
end)


killBrick.Anchored = true
killBrick.CanCollide = true

2 Likes

Trying this script now Working 100%

1 Like

Nice good luck Thank you guys im have idea

2 Likes

All they have to do is paste the code into the explorer

Great job. You now taught them how to use Cntrl C + Cntrl V. They didn’t actually learn anything at all.

3 Likes

That’s the point of tutorial it teaches you how to use the script. You can learn the script and learn how it works but this tutorial isn’t a lecture or meeting seminar.

A good tutorial would explain how the pieces of code work and what they do, in this case it does NOT do that (no offense)

1 Like