How to ignore Accessories if they get hit

Sup!

I am making a fps game… and the issue is that if the bullet Raycasts… the Accesories of an avatar are counting as a part, because of the Handle’s.
I tried to fix this, but didn’t manage to, so i decided to ask you!

The script that has the error:

local Hit = workspace:Raycast(bullet.Position, bullet.CFrame.LookVector * velocity * 1.5)
local HeadShot = false

	
if Hit then
	local HitCharacter = Hit.Instance.Parent
	local Humanoid = Hit.Instance.Parent:FindFirstChild("Humanoid")
	local HRP = Hit.Instance.Parent:FindFirstChild("HumanoidRootPart")
	if Hit.Instance ~= Hit.Instance:FindFirstChild("Handle") then
	
			if HitCharacter and Humanoid then
			
			if HitCharacter ~= killer.Character then
				
				if Hit.Instance == Hit.Instance.Parent:FindFirstChild("Head") then
					HeadShot = true
					
				end
				print(Hit.Instance)
				damage:FireServer(Hit.Instance.Parent, killer, HeadShot, CA)
				HeadShot = false
				return
			else
				
				return
			end
			
		elseif Hit.Instance == Hit.Instance:FindFirstChild("Handle") or HitCharacter:IsA("Accessory") then
			print("a")
		else

			print("ow")
			Loop:Disconnect()
			bullet:Destroy()
			return
		end
	end
end
3 Likes

Create some new RaycastParams and set the ignore list to be the player’s accessories [1] Then, just use the RaycastParams as the 3rd parameter for workspace:Raycast()

[1] =

local Ignore = {}
for i, v in Character:GetChildren() do
  if v:IsA(“Accessory”) then
       table.insert(Ignore, v)
   end
end

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = Ignore
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.