How would I detect when one part touches another part then fire off some code? One part must be unanchored.
There are two ways to do this, Touched and Raycasting, I will only go over the Touched event method since the other one is much more complex. If you are using this for a combat system (like a gun) then you need to use Raycast since Touched may have a delay or not fire. However, for general uses, Touched is fine.
Here is the code:
local primaryPart = game.Workspace.Part1 -- Change this to be the part you want the detections to run from. local targetPart = game.Workspace.Part2 -- Change this to be the part that should be checked against local function onTouch(touchedPart) if touchedPart == targetPart then -- Code here for what you want to happen when they touch end end primaryPart.Touched:Connect(onTouch)
It does not matter which part you choose as the primary one and which you choose as the target one. Ideally, the part which is touching the least number of other parts should be the primary one so the event isn't fired unnecessarily, but this is not needed.