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 find a player name by a mouse click?

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.

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

1 comment

0

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

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