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