How to reference collision groups in a script?

I’ve been messing around with collision groups and I have a pre-made group with an object that doesn’t collide with anything.

I want a specific part to collide with it, but it has to be created through a script. That means I also have to create a separate group in my script. How can I reference the pre-made collision group from my script so that I can set these objects to collide with each other?

.

2 Likes

Use PhysicsService

1 Like

I am using it to create another collision group, but how would I reference a collision group in a script that was already made?

1 Like
int[] GetCollisionGroups();

Just use this and index the right Collision group

2 Likes

if you created it with the collision groups editor or a script, then just use the name you created it with.

1 Like

I’m kind of assuming that the group I created is the one after the default. However, the code below doesn’t work for me.

[17:45:06.702 - Unable to cast value to std::string]

-- Adds beamEnd to beamCollision group
PhysicsService:SetPartCollisionGroup(beamEnd,beamCollision)
	
local collisionGroups = PhysicsService:GetCollisionGroups()
local invisibleGroup = collisionGroups[2]
	
PhysicsService:CollisionGroupSetCollidable(beamCollision,invisibleGroup,true)
1 Like

But, the name would have to track back to the collision group I want to reference, which is where I am having a difficult time figuring out.

1 Like

Because you’re using “SetCollidable”, you should just give the name if the collision group you supplied as Arg1 and Arg2 are strings

3 Likes

Each value of the table returns by GetCollisionGroups is also a table.

Please read the documentation on both itself and the collidable method.

Even if it were the second one (bold assumption to make) then you’d need collisionGroups[2].name for the name.

2 Likes

Thank you for the clarifications. I never knew I could click the different functions and see more in-depth details. Sorry about that.

1 Like