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

How to get Mouse.Target on mouse click?

Asked by
Lazarix9 245 Moderation Voter
5 years ago

What I am trying to do here is when a tool is equipped and left click is clicked, if the cursor is aiming at fixp, zwire, rwire or gwire, some parts' transparencies should change. This is a localscript and i put it in the tool which is supposed to be equipped:

--Variables
local tool = script.Parent
local fixwire = game.Workspace.bluewirefix
local fixp = game.Workspace.fixp
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Target = Mouse.Target
local zwire = game.Workspace.zwire
local gwire = game.Workspace.gwire
local rwire = game.Workspace.rwire

--Script
tool.Equipped:Connect(function(Mouse)

        Mouse.Button1Down:Connect(function()

            if Target == fixp or Target == zwire or Target == gwire or Target == rwire then

                zwire.Transparency = 1
                fixwire.Transparency = 0
                print("g")

        end     
    end)
end)


No errors in output are shown. What am I doing wrong? ;-;

1 answer

Log in to vote
0
Answered by 5 years ago

You need to say local Target = Mouse.Target on line 16, not on line 7. On line 7 you're getting the mouse target when the script loads up - when Mouse.Target changes, your Target variable isn't updated.

0
Oh. Thank you ^^ Lazarix9 245 — 5y
Ad

Answer this question