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

Is there a function that would start when two parts touch?

Asked by 9 years ago

So for example if you had part1 and part2, and you want something to happen when the two parts touch, is there a function for that? kind of like the onTouched function but i'm pretty sure that one only works when a humanoid touches the object. Thanks for any help guys!

0
onTouched, but you would need to add "if" statements and such. PreciseLogic 271 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

OnTouched works for anything. It does not have to be a humanoid.

So:

part1.Touched:connect(function(hit)
    if hit == part2 then
        print("Part1 was touched by Part2")
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

The touched event fires on anything that hits it. Keep in mind it's called Touched and not onTouched!

Part1 = workspace.Part1
Part2 = workspace.Part2

Part1.Touched:connect(function(Hit)
    if Hit == Part2 then
        print("Hit")
    end
end)
0
this is awesome! how can i make sure that this is constantly checked (like that the script keeps checking to make sure the parts are still touching) Gwolflover 80 — 9y

Answer this question