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

How to make mouse ignore certain objects?

Asked by 6 years ago

So I know about mouse.TargetFilter but I believe it has to be predetermined. How would I go about where there is a part called "IgnorePart" and when a player clicks on it, it ignores it and checks the Mouse.Target of the object behind it?

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

This is how you would check when the player clicks and get the part behind an object in a local script.

local Mouse = game.Players.LocalPlayer:GetMouse()
local Ignore = game.Workspace:WaitForChild("IgnorePart")

Mouse.Button1Down:Connect(function()
    if Mouse.Target == Ignore then
        Mouse.TargetFilter = Ignore

        local Target = Mouse.Target
        print(Target)

        Mouse.TargetFilter = nil
    end
end)
0
I appreciate the help, but by the looks of it the part is already predetermined or defined with local Ignore = ..., how would I set it to check if a part is "Ignore" and then set it to ignore. Marmalados 193 — 6y
0
I see what you mean, give me a minute to type a reply. Vmena 87 — 6y
0
You could have a IntValue or something that isn't physical and name it "Ignore", then when you click on an object check if it has a child called "Ignore". TheRighteousBuilder 70 — 6y
0
That makes no sense and is not what he is looking for, I posted my answer for what he wanted to do. Vmena 87 — 6y
0
How is that not what he's looking for? When you click on an object, it checks if it has an item called "Ignore" inside and if it does, then set the target filter to that object and then get the new target. TheRighteousBuilder 70 — 6y
Ad
Log in to vote
1
Answered by
Vmena 87
6 years ago
Edited 6 years ago

Since TargetFilter has to be predetermined you would make a ServerScript that searches through workspace and creates a folder of all the ignore objects. You would then create a remote event that sends the folder to the client when they spawn so that can be added to their personal target filter.

-- Server Script

local IgnoreFolder = Instance.new("Folder",workspace) -- We need to create a folder to store the ignored parts as the TargetFilter can only be set to one object. (which includes the object's children)

for i,v in pairs(game.Workspace:GetChildren()) do -- Runs through children of workspace
    if v.Name == "IgnorePart" then -- checks if their name is IgnorePart
        v.Parent = IgnoreFolder
    end
end)

game.Players.PlayerAdded:connect(function(plr)
    game.ReplicatedStorage.IgnoreEvent:FireClient(plr, IgnoreFolder)
end)

And then you would use your local script to add it to the target filter:

-- Local Script

game.ReplicatedStorage.IgnoreEvent.OnClientEvent:connect(function(IgnoreFolder)
    Mouse.TargetFilter = IgnoreFolder
end)

Glad I could help!

0
Much appreciated! I will deconstruct this and manipulate it somehow Marmalados 193 — 6y

Answer this question