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

2 bricks collide?

Asked by 10 years ago

I want to make it where when two bricks collide, something happens. But I have no idea how that works. I know other people have done it.

brick1 = game.Workspace.PushBrick
brick2 = game.Workspace.Button
function collide()
--stuff
brick1.Touched:connect(brick2)

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

A function is a block of code that we can ask to happen at some particular moment (for example, upon a collision).

Functions look like this:

function someFunctionName(someParameter)
    -- Code to do stuff here
end -- End function's block of code


An event , like Touched (for when a part touches any other part) calls a particular function that we connect to it.

In general, that looks like this:

someEvent:connect(someFunctionName)

For a Touched event, we could have a script that looks like this:

function collide(partColliding)
    if partColliding == brick2 then
        -- the part hitting `brick1` is `brick2`
        -- Let's do something in response!
        print("They hit")
    end
end

brick1.Touched:connect(collide)
0
I removed mine, since yours seemed like the better answer. Tempestatem 884 — 10y
0
Didn't work. Nothing in the output. Grenaderade 525 — 10y
Ad

Answer this question