I am trying to work on a script that sets every child’s collision group to 2 so the player cannot collide through the car, but the car can collide with objects. But when I try to use this script it doesn’t work.
local char = script.Parent
local children = char:GetChildren()
for i, child in ipairs(children) do
if child:IsA("MeshPart") or child:IsA("BasePart") then
child.CollisionGroupId = 2
end
end
I’ve checked the properties of the Character parts and it says the collisiongroupid is 2, but the player can still touch the car. Any way to fix this?
You are changing the collision group id of the car through your script, but you are not setting the collision group as non-collidable with the collision group of the player. Unfortunately, I do not know of a way to fix this by directly using the CollisionGroupId, but there are other ways to fix this.
The following is how roblox recommends you set the collision group of a part and includes a code sample:
By setting the collision group as shown above, you can then use the following function to change if the two collision groups can collide:
This will only work if the collision group of the player and the collision group of the car are set through the SetPartCollisionGroup function and are both in different collision groups.