How to ignore accessories through Raycasting?

I am trying to make a gun system in which once a player is shot, they will die. The problem is, when accessories are equipped, they act as a shield, and I do not want this to occur. I have been trying to find a way to solve this though I do not know how.

Local Script:

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local replicatedStorage = game:GetService("ReplicatedStorage")
local shootEvent = replicatedStorage:WaitForChild("ShootEvent")

local DAMAGE_AMOUNT = 100
local BULLET_HOLE_DECAL = "http://www.roblox.com/asset/?id=1844445084"
local BULLET_HOLE_SIZE = Vector3.new(1, 1, 0.001)
local OFFSET_DISTANCE = 0.001
local MAX_PROXIMITY = 0.1
local bulletHolePositions = {}
local debounce = false

local function bulletHoleExists(position)
	for _, pos in ipairs(bulletHolePositions) do
		local distance = (pos - position).Magnitude
		if distance <= MAX_PROXIMITY then
			return true
		end
	end
	return false
end

local function createBulletHole(position, normal)
	local adjustedPosition = position + normal * OFFSET_DISTANCE
	if bulletHoleExists(adjustedPosition) then
		return
	end

	local bulletHole = Instance.new("Part")
	bulletHole.Size = BULLET_HOLE_SIZE
	bulletHole.Anchored = true
	bulletHole.CanCollide = false
	bulletHole.CFrame = CFrame.new(adjustedPosition, adjustedPosition + normal)
	bulletHole.Transparency = 1
	bulletHole.Name = "BulletHole"

	local decal = Instance.new("Decal")
	decal.Texture = BULLET_HOLE_DECAL
	decal.Face = Enum.NormalId.Front
	decal.Parent = bulletHole

	bulletHole.Parent = workspace
	table.insert(bulletHolePositions, adjustedPosition)
	game.Debris:AddItem(bulletHole, 10)

	delay(10, function()
		for i, pos in ipairs(bulletHolePositions) do
			if pos == adjustedPosition then
				table.remove(bulletHolePositions, i)
				break
			end
		end
	end)
end

local function shoot()
	if debounce then return end
	debounce = true

	if not player.Character or not player.Character:FindFirstChild("Head") then
		debounce = false
		return
	end

	local fireSound = tool:FindFirstChild("fire")
	if fireSound then fireSound:Play() end

	local origin = player.Character.Head.Position
	local direction = (mouse.Hit.p - origin).unit * 1000

	local rayParams = RaycastParams.new()
	rayParams.IgnoreWater = true
	rayParams.FilterType = Enum.RaycastFilterType.Exclude

	-- Exclude accessories directly by adding them to the filter table
	local filterTable = {player.Character}
	for _, accessory in ipairs(player.Character:GetChildren()) do
		if accessory:IsA("Accessory") then
			table.insert(filterTable, accessory)
		end
	end
	rayParams.FilterDescendantsInstances = filterTable

	local raycastResult = workspace:Raycast(origin, direction, rayParams)

	if raycastResult then
		local hit = raycastResult.Instance
		local position = raycastResult.Position
		local normal = raycastResult.Normal

		if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
			shootEvent:FireServer(hit.Parent, DAMAGE_AMOUNT)
		else
			if hit.Parent and not hit.Parent:FindFirstChildWhichIsA("Accessory") then
				createBulletHole(position, normal)
			end
		end
	end

	task.delay(1.5, function() debounce = false end)
end

tool.Activated:Connect(shoot)

why are you handling the raycasting on the client???

but anyhow what i would do is when the player spawns, get all of the players accessories and turn can query off on their handles

server script

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		for i, v in pairs(character:GetChildren()) do
			if v:IsA("Accessory") then
				v:FindFirstChild("Handle").CanQuery = false
			end
		end
	end)
end)

AppearanceLoaded is finicky so I would use Child added + loop and just check if it’s an accessory

how is appearance loaded finicky

Sometimes appearance doesn’t load, and the event requires all accessories to exist before it’s fired. Most of the time it’ll work, but using ChildAdded is safer.

isnt that a good thing? when the event is fired all the accessories exist so, it would be safer no?

isnt that rare and a roblox issue?

You want to account for all the accessories no matter if some haven’t loaded in or not. Yes it would be a Roblox issue if the accessories don’t load in, but that’s why you want to make sure it’s handled.

im not understanding, by the time appearance loaded fires, all of the accessories have been loaded, i’m not understanding why to use child added. like i understand child added would also work but if appearance loaded fires when everything has been loaded then why not just use that, why would it be finicky

for the roblox issue part, there is no need to even do this at all because, the character doesnt have any accessories to begin with.

I’m pretty sure it’s possible for some but not all accessories to not load. I can’t really help you understand my point, but I’m just saying that AppearanceLoaded is weird sometimes. Also it doesn’t account for if you add accessories into a character, but that wasn’t really what this post was about.

I just use characteradded and then turn off can query, character appearance works too, there are no problems. Lastly the only way to do this is loop + if so there isnt anything else…