Hi, I'm quite new to scripting and I was wondering how to make a function that finds a player name by clicking on their character and then printing it? I've tried Mouse.hit but it hasn't seem to have worked.
COMMUNITY QUESTION
How would I find a player name by a mouse click?
1 answer
try this in a local script, put in startergui
local localPlayer = game:GetService("Players").LocalPlayer
local Mouse = localPlayer:GetMouse()
Mouse.Move:Connect(function()
local target = Mouse.Target:Connect(function(target)
if target.Parent:FindFirstChild("Humanoid") and target.Parent ~= game.Lightning or target.Parent ~= game then
Mouse.Button1Down:Connect(function()
local Character = target.Parent
local player = game.Players:GetPlayerFromCharacter(Character)
print(player.Name)
target:Disconnect()
end)
end
end)
end)
if it doesn't work then dm me at Blue Duck#8902
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
You typed in "Lightning" even though it is actually named "Lighting"