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:

01--Variables
02local tool = script.Parent
03local fixwire = game.Workspace.bluewirefix
04local fixp = game.Workspace.fixp
05local Player = game:GetService("Players").LocalPlayer
06local Mouse = Player:GetMouse()
07local Target = Mouse.Target
08local zwire = game.Workspace.zwire
09local gwire = game.Workspace.gwire
10local rwire = game.Workspace.rwire
11 
12--Script
13tool.Equipped:Connect(function(Mouse)
14 
15        Mouse.Button1Down:Connect(function()
View all 25 lines...

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