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

if Part1 touch Part2?

Asked by
OKRPLAY 25
8 years ago

Hello. I want to make that a Block with the name "Part1" detect if a Block with the name "Part2" touch the Block(with the name "Part1"). How it works?

0
game.Workspace.Part1.Touched:connect(function(part) if part.Name == 'Part2' then --[[Code]] end end) M39a9am3R 3210 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Part.Touched

Touched allows you to fire a function when one part touches another.

How do I do it?

Check if the Part it touched is called Part2

local Part1 = workspace.Part1;
Part1.Touched:connect(function(hit)
    if hit.Name == "Part2" then
        -- Touched!
        print("Touched")
    end
end)

This checks if a Part in Workspace touched a Part called Part2 and prints Touched if it did

Ad

Answer this question