Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.