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!

function deathTouch(part)

end

script.Parent.Touched:connect(deathTouch)

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

function deathTouch(part)

  if part then

  end

end

script.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).

function deathTouch(part)

  if part then
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    if plr then

    end
  end

end

script.Parent.Touched:connect(deathTouch)

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

function deathTouch(part)

  if part then
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    if plr then
      plr.Character:BreakJoints()
    end
  end

end

script.Parent.Touched:connect(deathTouch)

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

local touchers = { }

function deathTouch(part)

  if part then
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    if plr then
        local hum = plr.Character:FindFirstChild('Humanoid')
        if hum then
            local found;
            for _,v in pairs(touchers) do
                if v == plr.Name then
                    found = true
                end
            end
            if found then return end -- don't double damage
            hum:TakeDamage(20)
            table.insert(touchers, plr.Name)
            wait(1)
            local caught;
            for _,z in pairs(touchers) do
                if z == plr.Name then
                    caught = _
                end
            end
            table.remove(touchers, caught)
        end
    end
  end

end

script.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.