Issue with Collision Detection Not Working

I am trying to allow a player to spawn a part in (the server spawns it in, but the player dictates what and where), and have the part’s .Touched event not be triggered by the character of the player who spawned in said part.

The current issue is that despite setting up a collision filtering system, the character that touches the part can still trigger the .Touched event. Strangely enough the .Touched event is even being triggered by the character’s accessories after checking if hit:IsA(“BasePart”) (which to my knowledge should not be happening).

I’ve checked everywhere for a solution to this specific problem but haven’t found anything that seems to fit my needs. I’m not even sure of the exact cause of this problem so I apologize if this is confusing and will edit to be more specific as needed.

When a player joins a game, a module script will create corresponding collision groups:

--in module script
game.Players.PlayerAdded:Connect(function(player)
    PS:CreateCollisionGroup(player.Name) --collision group for player
    PS:CreateCollisionGroup(player.Name.."Spells") --collision group for player spells
    PS:CollisionGroupSetCollidable(player.Name, player.Name.."Spells", false)
    player.CharacterAdded:Wait()
    local x = player.Character:GetChildren()
    for i,v in pairs(x) do
        if v:IsA("BasePart") then
            PS:SetPartCollisionGroup(v, player.Name)
            print(v.Name) --Correctly prints the names of the parts being added to player's collision group (does not print accessory names)
        end
    end
end)

In another script, I have the server spawn in a part that the player wants. When the part is being spawned (from another script) it requires this function from the same module script.

--Called from the server script that is spawning in the part
local PI = require(ServerScriptService:WaitForChild("PlayerInfo")
local spell = ServerStorage.MagicParts.SpellName
local part = spell.Base:Clone()
PI.SetCollGroup(player.Name.."Spells",part)

This references the following function inside of the module script.

function PlayerInfo.SetCollGroup(name,part)
    PS:SetPartCollisionGroup(part,name)
end

The touch event and detection in the part that I’m checking for a collision

--in the script of the part that is spawned
local function onTouched(hit)
    if hit:IsA("BasePart") then
        print(hit.Name) --prints the character's parts including accessories even if the player spawned the part in.
        --other things happen
    end
end
script.Parent.Touched:Connect(onTouched) --listener for the touch event

Despite all of this, the part’s touched event will trigger after being touched by the player who spawned the part in, and it triggers on the player’s accessories as well. Please help me!

I have been made aware that .Touched events will fire even if the detected hit came from a part that should not be able to collide with the part that is being tracked for a touch event. An update to remedy this issue should be coming in a few weeks (as of 1/19/2021)

Until then, it is possible to check that the hit can collide with the part before running code:

script.Parent.Touched:Connect(function(hit)
     if hit:IsA("BasePart") and script.Parent:CanCollideWith(hit) then
          onTouched(hit)
     end
end)