Scripting Helpers is winding down operations and is now read-only. More info→
← Blog Home

So You Want To Make A Kill Brick, Eh?

Hey there! The Doc here, and today I'm doing to show you how to make a kill brick. Please note that this is a simple thing, but this was my application blog post so I wanted to share it. Thanks!

First, open Studio and insert a part using the context menu via right clicking.

Now select that part, and make it how you like. I made mine like lava.

Now highlight the part, and insert a script via the context menu.

This first method is going simply removing (destroy really) their head. To do that, we need to Add a touch event to the script. Open the script, and add the following. Feel free to name the function whatever your want!

1function deathTouch(part)
2 
3end
4 
5script.Parent.Touched:connect(deathTouch)

Currently that's an empty function. First, we need to see if the part that hit it is still there.

1function deathTouch(part)
2 
3  if part then
4 
5  end
6 
7end
8 
9script.Parent.Touched:connect(deathTouch)

If it's still there, it'll continue just fine. If not, it'll just stop running.

Next, we need to check if a player touched it. I use a nifty function called (this is also a link to the function on the wiki) GetPlayerFromCharacter(model).

01function deathTouch(part)
02 
03  if part then
04    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
05    if plr then
06 
07    end
08  end
09 
10end
11 
12script.Parent.Touched:connect(deathTouch)

Now we just need to call BreakJoints() on the character.

01function deathTouch(part)
02 
03  if part then
04    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
05    if plr then
06      plr.Character:BreakJoints()
07    end
08  end
09 
10end
11 
12script.Parent.Touched:connect(deathTouch)

And if you just want to do a certain amount of damage, replace the code with

01local touchers = { }
02 
03function deathTouch(part)
04 
05  if part then
06    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
07    if plr then
08        local hum = plr.Character:FindFirstChild('Humanoid')
09        if hum then
10            local found;
11            for _,v in pairs(touchers) do
12                if v == plr.Name then
13                    found = true
14                end
15            end
16            if found then return end -- don't double damage
17            hum:TakeDamage(20)
18            table.insert(touchers, plr.Name)
19            wait(1)
20            local caught;
21            for _,z in pairs(touchers) do
22                if z == plr.Name then
23                    caught = _
24                end
25            end
26            table.remove(touchers, caught)
27        end
28    end
29  end
30 
31end
32 
33script.Parent.Touched:connect(deathTouch)

In that last script there was quite a few things added, but I'll get into that in another post. I should also note that it is more extensive since it will not allow someone to get damaged twice in a one second period. Feel free to change the damage within the TakeDamage(20) section, and if you don't want a time out, just put a 0 for the wait(1).

That's it! Now admire your work, then go ahead and save it to your models! See you next time!

Posted in Scripting Tips

Commentary

Leave a Comment

M39a9am3R says: April 21, 2015
If this is a application blog post, why not choose something more complex? I think it would be appealing to the community if you explained a topic everyone is not familiar with. This would gain more attention and you would look like a expert on the topic.
DrJonJ says: April 21, 2015
Because I typed up my application on my phone. :P My next post will have a lot more put into it.
TheDarkOrganism says: April 21, 2015
It's nice to see another scripting blog post, instead of just text!
Goulstem says: April 22, 2015
This doesn't exactly explain why what you're doing works, you just sort of say that you're doing it and then do it.. Elaborate a bit.
legomaster38 says: April 22, 2015
Elaborate more you need to explain everything. You just sort of say that you're doing it but don't really explain every single concept in detail. If their are new users such as beginners online then they would like to see how well you do explaining every point and concept. That you used to make your script. Next time,tips to improve explain everything more. Be elaborative.
KenzaXI says: May 23, 2015
This script does the same thing but is much more simple and shorter. local Lava = script.Parent function onTouch(Brick) local Player = Brick.Parent:findFirstChild("Humanoid") if (Player ~= nil)then Player.Torso:Remove() end end Lava.Touched:connect(onTouch)
ChemicalHex says: May 28, 2015
Why couldn't you have just changed the humanoid's health? It would be much simpler for beginners.