How would I make a script and if I click on a player with the tool out itll print their name
COMMUNITY QUESTION
How would I make a tool that prints the players name that I click on?
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Do not spoon feed code.