I know about targetfilter but its not working for some reason. Basically I have a clickdetonator brick inside of a regular but bigger brick. I want to be able to make my mouse ignore the bigger brick in order to click the clickdetonator brick. Here is my code so far using targetfilter.
player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.TargetFilter = workspace.Pieces
Use ScreenPointToRay. There's a workspace function named :FindPartOnRayWithWhitelist
which allows the ray to pass through all objects that aren't in the 2nd argument.
https://developer.roblox.com/api-reference/function/Camera/ScreenPointToRay
mouse.TargetFilter
will only work if the mouse target is equal to the filter. Therefor, we can't use it to pass through objects.
local UserInputService = game:GetService("UserInputService") local Camera = workspace.CurrentCamera UserInputService.InputBegan:Connect(function(InputObject) --you should also use GameHandledEvent to check if the client clicks on a Gui element if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then local Direction = InputObject.Position local CPoint = Camera:ScreenPointToRay(Direction.X, Direction.Y) local NewRay = Ray.new(CPoint.Origin, CPoint.Direction * 5000) local Target = workspace:FindPartOnRayWithWhitelist(NewRay, {workspace.Pieces}) --the way will only hit this and its descendencies. if Target then print(Target.Name) --good to go end end end)