How to ignore bullet hole raycast?

I have a script that when a gun is shot it would cast a decal depending on the material it hits. For example if it hits plastic it will be a regular bullet hole, if it hits wood it would look like a wood bullet hole, and if it hits a player it would be a flesh wound. However if the player shoots a wound twice it would register that the player hit a plastic part instead of the player. How would I go on ignoring the flesh wound part that’s welded to the humanoid and instead just add another flesh wound instead of a bullet hole. The way my gun works is projectile based, they run off of OnTouched(). Im thinking about using different collision groups to bypass that but I am not sure if it would work or if there are more efficient methods.

https://i.gyazo.com/299c8052dd0ef5b22576930185e42f00.mp4

This is what I am talking about, notice how the bullet hole pops over the flesh wound. Sorry if quality is bad.

1 Like

For something which uses Touched, yes CollisionGroups would probably be best to use here.

It’d be pretty simple really, create the CollisionGroups:

local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CreateCollisionGroup("Wounds")
PhysicsService:CreateCollisionGroup("Projectiles")

Set them non-collidable:

PhysicsService:CollisionGroupSetCollidable("Wounds", "Projectiles", false)

And add them whenever needed:

PhysicsService:SetPartCollisionGroup(Projectile, "Projectiles")
PhysicsService:SetPartCollisionGroup(Wound, "Wounds")

If you don’t want to use CollisionGroups, then you could possibly create your own ignore table and inside the Touched check that the part you hit isn’t in the ignore table with a supplementary function:

local Ignore = {}

table.insert(Ignore, Wound)

local function notIgnored(part)
    for _, ignoredPart in ipairs(Ignore) do
        if ignoredPart == part then
            return false
        end
    end
    return true
end

Projectile.Touched:Connect(function(hit)
    if notIgnored(hit) then
        --// Code
    end
end)

Alternatively, you could use Rays and :FindPartOnRayWithIgnoreList() which would possibly be much easier and something that I’d prefer to use.

2 Likes

As Returned said, You could do raycast ignorelist create a Folder in the workspace and then put a bullethole’s parent inside the folder you created in the workspace and then when you do a raycast, you will raycast it and then ignore the Part inside the folder or to be exactly, workspace:FindPartOnRayWithIgnoreList(ray,workspace[Your Folder’s Name]) --don’t forgot to put the player’s character inside the ignorelist