Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to ignore certain parts when clicking, help?

I'm making a gun, and want to make it so that when you click the mouse ignores Non Collide parts. I investigated to see how to Ignore parts and found one:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Descendants = game.Workspace:GetChildren()
local IgnoreList = {}

for i, v in pairs(Descendants) do

	if v:IsA("Part") and v.CanCollide == false then

		table.insert(IgnoreList, v)

		mouse.TargetFilter = v

	end

end

for i, v in ipairs(IgnoreList) do

	mouse.TargetFilter = v

end	

This script does look correct, but I don't know where to place it.. Here's the mouse detect script:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Descendants = game.Workspace:GetChildren()
local IgnoreList = {}

script.Parent.Equipped:Connect(function(mouse)
	
	mouse.Button1Down:Connect(function()
		
		local Gun = script.Parent:FindFirstChild("Gun")
		
		script.Parent.Event:FireServer(Gun.Start.Position, mouse.Hit.p)
		
	end)
	
end)

I don't know if I should change My script or just add this code to it, If I do have to add it, where do i put it?

1 answer

I solved it lol Here's the new script:

mouse.Button1Down:Connect(function()
		
		if mouse.Target:IsA("Part") and mouse.Target.CanCollide == false then
			
			mouse.TargetFilter = mouse.Target
			
		end
		
		local Gun = script.Parent:FindFirstChild("Gun")
		
		script.Parent.Event:FireServer(Gun.Start.Position, mouse.Hit.p)
		
	end)

Basically it checks if the part clicked has collison off, if it has, it ignores it.

This discussion is preserved as it was. New answers, comments, and votes are closed.