How to add all accessories in a game to raycast ignore list?

Just wondering how would i be able to get all accessories on npcs and players and add them to a ignore list?

4 Likes

Hi!

So, why not just put the whole NPC character or Player Character on the Blacklist instead? :slight_smile:

Otherwise just do:

for _, Child in pairs(Character:GetChildren()) do
if Child:IsA("Accessory") then
--Add to blacklist
end
end
2 Likes

not trying to blacklist the entire npc because i need to kill the npcs, and for the players there will be specific pvp zones

Then do as I did above, and check for all accessories in a character. :slight_smile:

And add/remove it from blacklist to your liking.

how would i make it go through like a folder of npcs?

Well…

´´´lua
local NPCFolder = …

for _, Character in pairs(NPCFolder:GetChildren()) do
if Character:IsA(“Model”) and Character:FindFirstChildWhichIsA(“Humanoid”) then
–Loop here
end
end

(edit)
changed the code and got it to print the accesory but im pretty sure it doesnt add it to the table or something?

for i, v in pairs(NPCFolder:GetChildren()) do
	if v:IsA("Model") and v:FindFirstChildWhichIsA("Humanoid") then
		for _, v2 in pairs(v:GetChildren()) do
			if v2:IsA("Accessory") then
				table.insert(CastP.FilterDescendantsInstances, v2)
			end
		end
	end
end

boosting for a answer to this (char limit)

Hi!
Are you sure about that the accessories will be detected by the raycast in the first place? :slight_smile:

im pretty sure it does, i printed the hit and it hits the accessory’s handle

You could do something simple like

for _, Object in pairs(Character:GetDescendants()) do
if  Object:IsA("BasePart") and Object.Parent:IsA("Accessory") then
--Put object in Blacklist
end
end

Done. :slight_smile:

Edit: Or take my first sample, where we’re only looking for accessories inside the Character. If you blacklist a accessory, then it will include all the descendants that the accessory might include, which is what you aim for. :slight_smile:

ill try this but just wondering

table.insert(CastP.FilterDescendantsInstances, v2:FindFirstChild("Handle"))

wouldn’t this work? or is there something im missing

also does it matter if im running the function when the tool gets equipped?

Test out your script, make prints, even try to print the table that you’re trying to blacklist. Try and troubleshoot it.

local function onEquipped()
	CastP.FilterDescendantsInstances = {tool.Parent, BFolder}
	local NPCFolder = game.Workspace.Mobs

	for i, v in pairs(NPCFolder:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChildWhichIsA("Humanoid") then
			for _, v2 in pairs(v:GetChildren()) do
				if v2:IsA("Accessory") then
					print(v2)
					print(v2:FindFirstChild("Handle"))
					print(CastP.FilterDescendantsInstances)
					table.insert(CastP.FilterDescendantsInstances, v2)
					table.insert(CastP.FilterDescendantsInstances, v2:FindFirstChild("Handle"))
					print(CastP.FilterDescendantsInstances)
				end
			end
		end
	end
end

it prints the accessory and its handle, im just not sure why its not being added to the table
and for the table it prints before and after with no change to it whatsoever
image
image

local FilterTable = {}
	for i, v in pairs(NPCFolder:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChildWhichIsA("Humanoid") then
			for _, v2 in pairs(v:GetChildren()) do
				if v2:IsA("Accessory") then
					table.insert(FilterTable, v2)
				end
			end
		end
	end
CastP.FilterDescendantsInstances = FilterTable

Uncertain if this works, try it :slight_smile:

2 Likes

this did work, ty! (character limit)

Np! Feel free to return if you got any further questions!