How do I set the Mouse.TargetFilter to the entire workspace except for a specific folder. Just like the title says. Is there a way to do it so its like
Mouse.TargetFilter = game.workspace /exclude the folder which is also in the workspace
Thanks
Put everything you want the mouse to filter inside a folder and assign a reference to that folder instance to the mouse’s TargetFilter
property.
mouse.TargetFilter = workspace.Folder
Unfortunately Mouse.TargetFilter sucks and it’s very difficult to do what you want to do with it.
Fortunately it’s very easy to create your own mouse ray cast with whitelist support.
--Fire this each mouse click or whenever you need to check
local Mouse = game.Players.LocalPlayer:GetMouse()
local camera = workspace.CurrentCamera
local unitRay = camera:ViewportPointToRay(Mouse.X, Mouse.Y)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
raycastParams.FilterDescendantsInstances = {workspace.InsertFolderHere}
local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, raycastParams)
if raycastResult then
print(raycastResult.Instance.Name)
end
It didnt work with the filter so I removed it and it just prints baseplate no matter where I click
Thats the opposite of what I want. I want to put the whole workspace in the filter except that folder not the other way round
But you can’t, you can only assign a single instance to the mouse’s TargetFilter
property. Hence you’ll need to use my suggestion.
TargetFilter is only intended to be used for a single instance. Its single-instance nature doesn’t make it very powerful or configurable, so what you should do instead is mock mouse targeting with raycasting and include your specific folder as a blacklisted object in the RaycastParams.
You will need ViewportPointToRay to construct a unit ray between the mouse’s current X and Y positions, then feed the origin and direction (as well as any extension to the length by multiplying direction) to the raycast function. Your RaycastParams should have the folder as a FilterDescendantsInstance and the FilterType should be Blacklist.