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

How to get the name of the object the mouse was pressed on?

Asked by 5 years ago

Hi! I want to print in the Output a model's name when the player presses it But I don't really know how. I don't want to use ClickDetector, just the mouse.

Script:

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

mouse.Button1Down:Connect(function()
    print("Mouse has been pressed on")
end)

1 answer

Log in to vote
1
Answered by
BashGuy10 384 Moderation Voter
5 years ago
Edited 5 years ago

There is a super cool value of "mouse" call "Target", i will explain how to do this below:

Basics of mouse.Target: 1. What ever the mouse is pointed at, it will return it. 2. You can use this to change values of the part.

Simple script explaining how to do it:

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

mouse.Button1Down:Connect(function()
    print("Mouse has been pressed on: "..mouse.Target.Name)
end)

So, if you clicked on a part named "Bricky", it would print:

Mouse has been pressed on: Bricky

Please mark this as the answer if it helped!

EPIC DEVELOPER HUB LINK!1!!!!11111111!!!!!!1!!!11111!!111!11111!!!!11111: EPIC DEVELOPER HUB LINK

Ad

Answer this question