Can you disable Touched event for parts in Collision Groups that don't collide?

I have a set of collision groups that are setup not to collide with each other, and they don’t, but the Touched event still fires when parts in those collision groups pass through each other. Is there a way to disable the Touched event for non-colliding groups? Or do I need to code some if statements to check if the colliding parts’ collision groups can collide?

2 Likes

In your touched event, you can determine whether the part that touched the other part is in a certain collision group, and if it is, skip the code entirely. This seems like intended behaviour, as parts with CanCollide false still fire the touched event.

1 Like

You can use PhysicsService to identify if the part is or is not in a collision group, then you can just return nil if it isn’t

1 Like

Have you tried doing a check with CanCollideWith?

http://wiki.roblox.com/index.php?title=API:Class/BasePart/CanCollideWith

Simple code of

BasePart.Touched:connect(function(hit)
    if BasePart:CanCollideWith(hit) then
        --code
    end
end)
9 Likes

Thank you very much, I did not know this function existed. This will be much cleaner than trying to check which collision group the parts are in and if those collision groups collide because the parts change collision groups at times. Would have had to do a long if-statement with lots and and’s and or’s.