Can't sort collision groups for race car through scripts

Hello!
I am attempting to turn off collisions between my race cars and between the players through a script.

My race cars use A-chassis, a car chassis which creates parts for suspension after the game starts, meaning I cannot add them to a collision group through the collision menu in studio since they don’t exist yet!

Changing the collision groups through the collision menu once I’ve started playtesting solves my issues, however this will not be possible in-game.
Since SetPartCollisionGroup only works for parts, this would mean I need to list every part individually for 20 cars. I could use GetDescendants, however I am unsure how to use them to set collisions!

I hope I’ve explained it well, I’m a complete dumb dumb but it’s something that goes right over my head!

Have you tried using PhysicsService | Roblox Creator Documentation?

Example usage:

local Part = workspace.TestPart
local PhysicsService = game:GetService("PhysicsService")

PhysicsService:SetPartCollisionGroup(Part, "InsertGroupNameHere")
1 Like

I mentioned in my first post that I had tried this, however since the car is a group, and not a part, I get the error “Parameter 1 must be BasePart in SetPartCollisionGroup.” Would there be a way to find the parts in the car and then set the parts that way? Thanks :slight_smile:

That makes it a bit tougher. Unfortunately, Roblox doesn’t have any functions that let you set the collision group of a model (they should though). You’d probably just have to loop through it or make a template object that gets cloned that already has the collision group.

Sorry for missing that detail of the first post though!

--//Services
local PhysicsService = game:GetService("PhysicsService")

--//Variables
local RaceCar = workspace.RaceCar

--//Loops
for i, Descendant in ipairs(RaceCar:GetDescendants()) do
	if Descendant:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(Descendant, "InsertGroupNameHere")
	end
end