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

Is there any way to "whitelist" a BasePart from being the mouse's target?

Asked by 4 years ago

Hello friends. I am making a placement system and I have found myself stuck at a little problem. When placing the object, I need to check the mouse's target is a panel from the base. Anyways, for this, I need to use mouse.Target. But the problem with doing this is that the mouse's target will always be the part I'm dragging. I've tried things to kind of "whitelist" the part from being detected such as making the part locked. This hasn't worked and I was wondering if anybody had a solution to my problem.

This is the code for the problem: (This is just a piece of the code. All variables are defined.)

local assets = replicatedStorage.CoreModule.Assets
local clone = assets.Placeable:FindFirstChild(object.Name)
local placeEvent = replicatedStorage.CoreModule.Events.BuyBuild

if clone then
local panel
print(mouse.Target.Name)
if mouse.Target and mouse.Target.Name:find("Panel") then
    local base = mouse.Target.Parent.Parent

    if base and base.Name:find("Base") then
        print'oh base yes'
        local config = base:FindFirstChild("Configuration")

        if config and config:FindFirstChild("Owner") then
            if config.Owner.Value.Name == player.Name then
                panel = mouse.Target
            else
                panel = "CannotPlace"
            end
        end
    end
end

2 answers

Log in to vote
0
Answered by
noammao 294 Moderation Voter
4 years ago
Edited 4 years ago

Hi. Have you tried using mouse.TargetFilter = workspace.BlockedPart?

workspace.BlockedPart Isn't the actual object. Change that to the item you don't want to block your mouse ray.

0
I tried that for the model not the part it's self. I'll try it. namespace25 594 — 4y
0
It doesn't work. namespace25 594 — 4y
0
oh crap. I wasn't using the object that was on the players mouse as the target filter. namespace25 594 — 4y
0
Glad I could help :) Also, I really don't like to ask but could you upvote me please, if it's not a bother? I really want and am really close to get to the next reputation rank. noammao 294 — 4y
Ad
Log in to vote
0
Answered by
Upbolt 20
4 years ago
Edited 4 years ago

Just create a table, with the whitelisted part as the key. When you check for the mouse target, just have an if statement that checks if the current target is a valid index in the table

0
This wouldn't work. The mouse is always hovering over the part. namespace25 594 — 4y

Answer this question