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

How would I make a tool that prints the players name that I click on?

How would I make a script and if I click on a player with the tool out itll print their name

1 answer

For this, you'd want to use Mouse.Target which is the object that the mouse is currently pointing to.

--Local script inside the tool
local Tool = script.Parent
local Player = game.Players.LocalPlayer

Tool.Activated:Connect(function()
	local Mouse = Player:GetMouse() --Get the player's mouse
	local target = Mouse.Target --Read what the mouse is pointing to
	if not target then return end --Return if the target is nil, as to prevent errors

	print(target.Name) --Print the name of the object the mouse is pointing to
end)

1 comment

0

Do not spoon feed code.

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