Raycast ignoring too many parts

I’m trying to make a gun system that ignores parts that have CanCollide disabled, but for some reason, when I add an accessory to an ignore list, the script ignores the whole character. I’ve looked at other posts, but none of them seem to have this issue. Here’s a piece of the code:

repeat
	touch, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, currentIgnore,false,true)
	print(table.unpack(currentIgnore))
	print(touch)
	if not touch then break end

	local function isRight()
		if touch.CanCollide == true then
			return true
		end

		table.insert(currentIgnore, touch)
		return false
	end
until isRight() == true

Here’s a video of it:

I’m pretty sure its because the accessory is welded and is part of the character here try this

repeat
	touch, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, currentIgnore,false,true)
	print(table.unpack(currentIgnore))
	print(touch)
	if not touch then break end

	local function isRight()
		if touch.CanCollide == true then
			return true
		end

		if touch.Parent:IsA("Accessory") then      
			table.insert(currentIgnore, touch.Parent)
                     touch.Parent:Destroy() and script.Disabled = true -- its disable or disabled
                    until 
               -- just assuming this is part of your shooting script 
                player.shooting = true  
               script.Disabled = false
		end
		return false
	end

I dont like to touch guns but I think this should work.

if it doesn’t please reply to me with the output.

signed,
X

1 Like

Sorry, I’ve just realised that I need to ignore all cancollide false parts, here’s the new script:

repeat
	touch, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, currentIgnore,false,true)
	print(table.unpack(currentIgnore))
	print(touch)
	if not touch then break end

	local function isRight()
		if touch.CanCollide == true then
			return true
		end

		table.insert(currentIgnore, touch)
		return false
	end
until isRight() == true

I’ve tried to add only the part to the ignore list rather than the whole accessory, but it still doesn’t work. Do I need to ignore the accessory and its weld instead?

yes try ignoring both.

signed,
X

Nevermind, I just put all characters into a table and add their accessories to an ignore list, but thank you for your time:

local players = game.Players:GetPlayers()
local characters = {}
local accessories = {}

for i, v in pairs(players) do
	table.insert(characters, v.Character)
end

for i, v in pairs(workspace:GetChildren()) do
	if v.Name == "Dummy" then
		table.insert(characters, v)
	end
end

for i, v in pairs(characters) do
	for i, ve in pairs(v:GetChildren()) do
		if ve:IsA("Accessory") then
			table.insert(accessories, ve)
		end
	end
end

repeat
	for i, v in pairs(accessories) do
		table.insert(currentIgnore, v)
	end

	touch, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, currentIgnore,false,true)
	if not touch then break end

	local function isRight()
		if touch.CanCollide == true then
			return true
		end

		table.insert(currentIgnore, touch)

		if touch.Parent.Parent:FindFirstChild("Humanoid") then
			for i, v in pairs(touch.Parent.Parent:GetDescendants()) do
				if v:IsA("Weld") then
					if v.Part0 == touch or v.Part1 == touch then
						table.insert(currentIgnore, v)
					end
				end
			end
		end

		return false
	end
until isRight() == true
1 Like