Help with collisiongroups

My problem is really simple but I’m really stuck

I want to call a collision group in a script so I can add and remove a part to it .

I cannot find any way how to do it

I searched in roblox developer hub and it still did not work. It kept saying in the output
“Argument missing or nil”
“false”

I would recommend posting your code here so others can help you with the issue you’re having :smiley:

Posting the script would surely help us trying to help you fix the problem.

We can’t really help unless we have the code.

Oh yea sorry, it’s my first topic but I didn’t make myself clear what I meant by this topic is that is there an easy way to call it. I’m not asking for my code to be fixed. I’m more asking in what way could I call it.

local PhysicsService = game:GetService("PhysicsService")
-- Create collision group
PhysicsService:CreateCollisionGroup("group1")
-- Add an object to each group
PhysicsService:SetPartCollisionGroup(instance, "group1")

tbh its pretty basic just remeber everytime you call it the group it must be a string

local PhysicsService = game:GetService("PhysicsService")
-- Create collision group
local group1 = "group1"
PhysicsService:CreateCollisionGroup(group1)
-- Add an object to each group
PhysicsService:SetPartCollisionGroup(instance, group1)

you could do this if you dont want to add “” but really to add a part you would just use setpartcollsiongroup

Collision Filtering | Documentation - Roblox Creator Hub

if you wanted to really make it simple you would just add a function for it

local PhysicsService = game:GetService("PhysicsService")
-- Create collision group
PhysicsService:CreateCollisionGroup("group1")
--function
local function SetCollision(part)
PhysicsService:SetPartCollisionGroup(part, group1)
end
-- to add an object just
SetCollision(object)

the basic thing is that the part is an instance that can be in a collision group

i know that i didn’t need to make this long but i did so i hope i helped

Hmmmmm well let me give you an example of what I want
So I want to reference one that already exists

local collgroup = (call the collisiongroup)
PhysicsService:SetPartCollisionGroup(v, collgroup)

but I don’t know how to call that collision group.

well you would make collgroup a string

local collgroup = "collgroup"
PhysicsService:CreateCollisionGroup(collgroup)
PhysicsService:SetPartCollisionGroup(v, collgroup)

you can call a collsion group by its id or its name

though to call it y its id you would use BasePart.CollisionGroupId

this page should help a bit
PhysicsService | Documentation - Roblox Creator Hub

1 Like

Alright thank you I think I understand better