Issues PhysicsService - "Collision group does not exist"

Hi! I am learning how to use this service and I get an error, ‘Collision group does not exist.’

what’s wrong? :confused:

local PhysicsService = game:GetService("PhysicsService")

local part1 = game.Workspace.Col1
local part2 = game.Workspace.Col2

local collisionGroup = PhysicsService:CreateCollisionGroup("Group1", "Group2")

local partsGroup1 = PhysicsService:CollisionGroupContainsPart("Group1", part1)
local partsGroup2 = PhysicsService:CollisionGroupContainsPart("Group2", part2)

local setCollidable = PhysicsService:CollisionGroupSetCollidable("Group1", "Group2", true)

print(setCollidable) -- should it print true?

if setCollidable == true then
   print('yes, both are')
else
   print('error! they are not collidable!')
end

ignore the script name:

image

1 Like

I still can’t fix this error… could someone give me a hand :pray:

It’s not a full solution. It still doesn’t work as intended, but this code runs with no errors:

local PhysicsService = game:GetService("PhysicsService")

local part1 = game.Workspace.Col1
local part2 = game.Workspace.Col2

local collisionGroup1 = PhysicsService:CreateCollisionGroup("Group1")
local collisionGroup2 = PhysicsService:CreateCollisionGroup("Group2")

local partsGroup1 = PhysicsService:CollisionGroupContainsPart("Group1", part1)
local partsGroup2 = PhysicsService:CollisionGroupContainsPart("Group2", part2)

local setCollidable = PhysicsService:CollisionGroupSetCollidable("Group1", "Group2", true)

print(setCollidable) -- should it print true?

if setCollidable == true then
print('yes, both are')
else
print('error! they are not collidable!')
end
1 Like

setCollidable can never be true because CollisionGroupSetCollidable function of PhysicsService is a void function and void functions always return nil.

1 Like

and why i can’t do something like this?
local createGroups = PhysicsService:CreateCollisionGroup("colsGroup1", "colsGroup2")

CreateCollisionGroup is expected to have 1 string

2 Likes

So the second parameter is ignored by the function.

2 Likes

It seems like I forgot something in this “fixed” code. I think that @blablablabon 's reply can be the solution for the post’s topic.

2 Likes

Thanks guys! but I made some improvements in the code but it still does not work, I do not understand what is wrong…

function checkCollidable(isBool)
	if isBool then
		print('yes, both are collidable!')
	end
	
	if not isBool then
		warn('error! they are not collidable!')
	end
end

local PhysicsService = game:GetService("PhysicsService")

local col1 = game.Workspace.Col1
local col2 = game.Workspace.Col2

local myParts = {col1, col2}

local createGroup1 = PhysicsService:CreateCollisionGroup("colsGroup1")
local createGroup2 = PhysicsService:CreateCollisionGroup("colsGroup2")
local addingParts = PhysicsService:CollisionGroupContainsPart("colsGroup1", myParts.col1)
local addingParts = PhysicsService:CollisionGroupContainsPart("colsGroup2", myParts.col2)

local setCollidable = PhysicsService:CollisionGroupSetCollidable("colsGroup1", "colsGroup2", true)

game.Players.PlayerAdded:Connect(function()
	wait(3)
	checkCollidable(setCollidable)
end)

That’s because you used a table and then wrongly called the table components.
Instead of local addingParts = PhysicsService:CollisionGroupContainsPart("colsGroup1", myParts.col1) local addingParts = PhysicsService:CollisionGroupContainsPart("colsGroup2", myParts.col2)
use local addingParts = PhysicsService:CollisionGroupContainsPart("colsGroup1", myParts[1]) local addingParts2 = PhysicsService:CollisionGroupContainsPart("colsGroup2", myParts[2])

2 Likes