How to filter out character accessories and tools with rays?

So this is my current blacklist, which works as intended, to make it so that rays don’t stop at MY OWN character:

local rayparams = RaycastParams.new()
rayparams.FilterType = Enum.RaycastFilterType.Blacklist
rayparams.FilterDescendantsInstances = {player.Character}

But I’m confused on how to make it so that the rays will hit another player, but completely ignore their accessories and tools.
I have a folder called “Entities” in workspace, which all player characters are loaded into.

I suppose you can loop through and get all the accessories?

local entities = workspace.Entities

local function getHats()
	local hats = {}
	
	for _, character in pairs(entities) do
		for _, child in pairs(character:GetChildren()) do
			if child:IsA("Accessory") then
				table.insert(hats, child)
			end
		end
	end
	
	return hats
end


print(getHats()) --> returns a table with all the hats in the game, assuming your characters are under "Entities" like you stated.

Here's an alternative without having to store your characters under a folder
local function getHats()
	local hats = {}
	
	for _, player in pairs(players:GetPlayers()) do
		local character = player.Character
		
		if character then
			for _, child in pairs(character:GetChildren()) do
				if child:IsA("Accessory") then
					table.insert(hats, child)
				end
			end
		end
	end
	
	return hats
end

And then you can simply do this on your code:

rayparams.FilterDescendantsInstances = {player.Character, table.unpack(getHats())}
2 Likes

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