Could not create collision group?

So I had this bug recently pop up in code that I haven’t touched for several weeks.
The code errors for no reason when I try to create a collision group.

This module function’s purpose is to remove collisions between player characters. Does anyone know why exactly my code breaks when I simply try to create a collision group? The error I am given tells me no useful information.

module.ToggleCollisions = function(bool)
	local physics = game:GetService("PhysicsService")
	if not bool then
		physics:CreateCollisionGroup("ActivePlayerCollisons") --error here
		physics:CollisionGroupSetCollidable("ActivePlayerCollisons", "ActivePlayerCollisons", false)
		local activePlayers = workspace.GameStuff.ActivePlayers:GetChildren()
		for i,v in pairs(activePlayers) do
			local player = game.Players:FindFirstChild(v.Name)
			if player then
				local char = player.Character
				if char then
					--recurse char body parts and hats
					module.PartsList = {}
					local NewParts = module.RecurseParts(char)
					for y, part in pairs(NewParts) do
						physics:SetPartCollisionGroup(part, "ActivePlayerCollisons")
					end
				end
			end
		end
	else
		physics:RemoveCollisionGroup("ActivePlayerCollisons")
	end
end

3 Likes

Means the collision group already exists.

game:GetService("PhysicsService"):CreateCollisionGroup("TEST")
game:GetService("PhysicsService"):CreateCollisionGroup("TEST")

Will cause the same issue

Unfortunately there aren’t any ways to check if a collision group exists by its name (Without erroring when it doesn’t exist) other than iterating over all collision groups with GetCollisionGroups

function collisionGroupExists(name)
    for _,v in pairs(game:GetService("PhysicsService"):GetCollisionGroups()) do
        if v.name == name then
            return true
       end
    end
    return false
end

You could always catch it with pcall but errors are prone to change

1 Like

Fret not, for I have the solution

Now try it with a name that doesn’t exist and get this Collision group not found.

3 Likes

Nice, that definitely shouldn’t be happening.

1 Like

Thank you for the help guys.

This error should definitely be better explained in the output.

1 Like

Hey Ripull, do you know if this code is executing from a LocalScript thread on the client or a server-side Script?

That’s the one thing that’s not clear here. I don’t believe it works on the client right now, which is something I have in my queue to fix (for setting at least, not creating).

1 Like

No no, this was server side.

Is it possible to change the error I received in the original post to “Could not create Collision Group, Collision group already exists” so that people encounter this mistake in future don’t get stuck on this like I did?

1 Like

Oh great, easy. So checking if the group exists first fixed it? I’ll fix that error message then.

Yes, this appears to be the case, my game has been running with this fix for 24 hours now and no more reports of issues.

Problem is that checking if the group exists and it doesnt will also error so youre gonna error either way.
Ive submitted a bug for this.

1 Like

Yep, also an issue. @ContextLost desired behavior is:

  • Calling CreateCollisionGroup for an existing group will just return the existing group
  • Calling GetCollisionGroupId/Name when the collision group doesn’t exist returns nil instead of throwing an error (this is Lua – not a lower level language like C++)
1 Like

Not sure if I’m experiencing the same error for a different reason, but anyone know if this has been fixed? I’ve got this:

image
Been having the error for a few months now, and since its not a very important part of a game I don’t develop much anymore I haven’t got round to fixing it. image

5 Likes