Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

2 bricks collide?

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

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)

2 comments

0

I removed mine, since yours seemed like the better answer.

0

Didn't work. Nothing in the output.

This discussion is preserved as it was. New answers, comments, and votes are closed.