Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Trying to ignore certain parts when clicking, help?

Asked by
ZIRFAL3 17
3 years ago

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

Log in to vote
0
Answered by
ZIRFAL3 17
3 years ago

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.

Ad

Answer this question