Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Could I Check If A Collision Group On PhysicsService Already Exists?

Asked by 4 years ago

So I Recently Stumbled Upon A Error In My Game It Says:

****Cannot Create Collision Group One Already Exists

So I Was Wondering How Could I Check To See If it Already Exists To Prevent Errors?

Here Is My Code:

physicsService = game:GetService'PhysicsService'
for i = 1,3 do
if physicsService:GetCollisionGroupName("Group"..i) then 
print("Collision Groups Exist!")
else
physicsService:CreateCollisionGroup("Group"..i)
end
end
physicsService:CollisionGroupSetCollidable("Group1", "Group2", false)

Please Help As I Have Not Seen This Error Before.

1 answer

Log in to vote
1
Answered by
OhManXDXD 445 Moderation Voter
4 years ago

I found a devforum post related to your error, you can try this

local PhysicsService = game:GetService("PhysicsService")

local function CreateCollisionGroup(collisionGroupName)
    local createdGroups = PhysicsService:GetCollisionGroups()
    local collisionGroupExists = {} do
        for _, createdGroup in pairs(createdGroups) do
            collisionGroupExists[createdGroup] = true
        end
    end

    if not collisionGroupExists[collisionGroupName] then
        PhysicsService:CreateCollisionGroup(collisionGroupName)
    end
end

CreateCollisionGroup("Group1")
CreateCollisionGroup("Group2")
PhysicsService:CollisionGroupSetCollidable("Group1", "Group2", false)

I don't have much experience with PhysicsService, so this may not work Post: https://devforum.roblox.com/t/script-erroring-that-a-collision-group-already-exists-when-it-doesnt/322318

0
Thanks I Will Try It Harry_TheKing1 325 — 4y
Ad

Answer this question