Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Kill brick fails to do anything?

Asked by 10 years ago
function onTouched(hit)
    if hit.Parent.Humanoid ~= nil then
        for i = 1, 20 do
            hit.Parent.Head.Size = hit.Parent.Head.Size + Vector3.new(0.5, 0.5, 0.5)
            wait()
        end
    hit.Parent.Humanoid.Health = 0
    end
end

The brick should make the player's head inflate and then kill the player. However, when I test it, nothing happens. There is no error in the output, but my guess is that I screwed up the function on line 1. Can anyone help?

1 answer

Log in to vote
1
Answered by
Minifig77 190
10 years ago

This function doesn't have an event listener attached to it. As of now, nothing will happen because nothing can trigger it!

Try this:

function onTouched(hit)
    if hit.Parent.Humanoid then
        for i = 1, 20 do
            hit.Parent.Head.Size = hit.Parent.Head.Size + Vector3.new(0.5, 0.5, 0.5)
            wait()
        end
    hit.Parent.Humanoid.Health = 0
    end
end
script.Parent.Touched:connect(onTouched) --Add a connection line

Also, quick suggestion:

Whenever you're checking to see if something is nil, all you need to do is:

if hit.Parent.Humanoid then

Because, by default, it'll check if it's nil unless told to do otherwise.

0
Oh, I feel stupid. Thanks! IcyArticunoX 355 — 10y
Ad

Answer this question