How do I blacklist a specific group of parts on Roblox?

527 Views Asked by At

Here's the problem: I'm trying to blacklist all parts that are non-collidable for my raycast weapon. I got the code that finds the blocks, and the codes that blacklists it, but it just won't fuse together. No matter what I do.

Here's the code I'm using:

local function Step(overrideDistance) -- Cast ray:

        local descendants = workspace:GetDescendants()

        for _, descendant in pairs(descendants) do -- Code that finds blocks that are non-collidalbe
            if descendant:IsA("BasePart") then
                if descendant.CanCollide == false then
                    return
                end
            end
        end
        
        local blackList = {script.Parent, workspace.TheBlueException} -- Blacklist code
        local params = RaycastParams.new()
        local direction = currentNormal * (overrideDistance or stepDistance)
        params.FilterType = Enum.RaycastFilterType.Blacklist
        params.FilterDescendantsInstances = blackList
        local result = workspace:Raycast(currentPos, direction, params)
        local pos

Hopefully this'll be enough information to see where the error lies. In any case, thank you for your time.

1

There are 1 best solutions below

0
Blarg On

Oh nevermind. It turns out I needed to add this to the function

local PhysicsService = game:GetService("PhysicsService")

local laserignore= "LaserIgnore"

PhysicsService:CreateCollisionGroup(laserignore)
PhysicsService:CollisionGroupSetCollidable(laserignore, "Default", false)

local descendants = workspace:GetDescendants()
for _, descendant in pairs(descendants) do
    if descendant:IsA("BasePart") then
        if descendant.CanCollide == false then
            PhysicsService:SetPartCollisionGroup(descendant, laserignore)
            descendant.BrickColor = BrickColor.Green()
        end
    end
end

Basically, I added a new thing entirely called "PhysicsService". Using this, I was able to create a new collision group entirely, completely separate from the original "Default" collision group. This way the local descendants' job is now to add this new collision group to the bricks I want to be non-collidable with my raycast, replacing the original "Default" collision group in the process. Then, the raycast laser will automatically go through the new collision blocks, because they are not considered "Default" in the collision group.

tl;dr, I figured it out, lol.