Still have questions? Join our Discord server and get real time help.
Log in to vote

How to wait until a specific collision group is added?

Asked by 11 months ago

In two different scripts, I'm creating a collision group. The objective is making it so that the collision groups made in each script don't collide with each other. The problem is that they both run at the same time meaning there is a chance the other group won't be created yet when it tells the server to make each group not be able to collide with each other.

How would you check if the collision group is already made or not?

1 answer

Log in to vote
Answered by
Avigant 2334 Moderation Voter Community Moderator
11 months ago

Well, technically speaking, scripts don't run at the same time. They run consecutively, and the order is determined by the thread scheduler. But aside from that, here's one option:

local Services = {
    Physics = game:GetService("Physics")

local function IsCollisionGroupExisting(Name)
    local IsSuccess = pcall(function()
        return Services.Physics:GetCollisionGroupId(Name)

    return IsSuccess

local Name = "Test"

if not IsCollisionGroupExisting(Name) then

Of course, a much better approach would be to use one Script and one LocalScript for your entire game, and have all of your code rest in modules, so you don't get potential threading bugs like this one.

Alternatively you could use a module that returns a table, and have both scripts check whether or not it was created that way. Avigant 2334 — 11mo

Answer this question