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

How do you make your mouse ignore a brick?

Asked by 5 years ago

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

1 answer

Log in to vote
0
Answered by
pidgey 548 Moderation Voter
5 years ago

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)

0
Ahh I figured it was something like that, I'll read up on this. Appreciate it man windstrike 27 — 5y
0
You can also use the clients mouse (x & y) to create the ray, however, I think ScreenPointToRay offers more and it's good practice to use it instead. pidgey 548 — 5y
0
Yeah I'm not that experienced with rays in general so this offers me a good chance to learn something new xD windstrike 27 — 5y
0
Hmm doesnt seem to work for me. It's still unable to pass through the part in order to click the clickdetonator. Instead its just printing the target.Name which matched a brick in the model pieces. Weird windstrike 27 — 5y
View all comments (2 more)
0
Yes, that's what the code does. Is that not what you were trying to do? Is ClickDetonator a part? pidgey 548 — 5y
0
Yeah I get how it works but the thing is I wanted to be able to click the clickdetonator brick when i click an accessory brick above it. It's fine though I can just this method and recode it to fit xD windstrike 27 — 5y
Ad

Answer this question