Hi! I am learning how to use this service and I get an error, ‘Collision group does not exist.’
what’s wrong?
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
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
setCollidable can never be true because CollisionGroupSetCollidable function of PhysicsService is a void function and void functions always return nil.
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])