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

How to access Mouse.Target parent?

Asked by 10 years ago

Hi guys, I need to get a parent of the part targeted by the mouse, I tried with something like this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function myFunction()
    if tostring(mouse.Target) == "MyBrick" then
        local instance = mouse.Target.Parent:FindFirstChild("InstanceID")
        instance.Value = 15;
    end
end

But that wont work, why?

1 answer

Log in to vote
0
Answered by 10 years ago

Not too sure why that didn't work, but gonna try to put my hand on it:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function myFunction()
    if mouse.Target then
        if mouse.Target.Name == "MyBrick" then
            local instance = mouse.Target.Parent:FindFirstChild("InstanceID")
            instance.Value = 15;
        end
    end
end

Also I hope you do call that function somewhere.

0
Let's see alessandro112 161 — 10y
0
Didn't work, I don't know why alessandro112 161 — 10y
0
Do you ever call that function? If you want that to happen when ever you click, you have to add this at end: mouse.Button1Down:connect(myFunction) ZarsBranchkin 885 — 10y
Ad

Answer this question