How would I see what player clicked on an object

I know, it’s really simple, I just don’t know how.

I haven’t found anything on it.

Basically, to explain further, I want this:
When a player clicks on something, the part is able to find the humanoid of the character.

This has been solved by many people, here are their posts:

1 Like

Are you using a click detector?

Edit: If Yes

ClickDetector.MouseClick:Connect(function(Player)
    print(Player.Name) -- This is who clicked it
end)
1 Like

Yes, it’s inside the part.
I want it when the click detector is clicked.

-- Place inside the part
local ClickDetector = Instance.new('ClickDetector')
ClickDetector.Parent = script.Parent

ClickDetector.MouseClick:Connect(function(playerWhoClicked) -- playerWhoClicked is the player
    local char = playerWhoClicked.Character
    local hum = char.Humanoid -- Your humanoid
end)
1 Like

You can use ClickDetectors for that! MouseClick's event actually gives the Player’s Object in the first parameter, and you can just simply do Player.Character.Humanoid to get the Humanoid

1 Like

Sorry if this seems really dumb, but would it matter if I put playerWhoClicked? (like the name)

You can define the player however you like.

E.g plr, player, playerwhoclicked etc. (Just make sure you replace the current one with what you desire.)

1 Like

Yes, that is the parameter which defines the player who clicked the part. playerWhoClicked is just the name used in the ClickDetector documentation, but it can be anything you want (it’ll always be player anyways)

1 Like
ClickDetector.MouseClick:Connect(function(YesHiIAmAPlayerObjectThatWasClickedOn)
    print(YesHiIAmAPlayerObjectThatWasClickedOn.Name)
end)
--Output: Jackscarlett
1 Like

If I don’t have the argument playerWhoClicked in my function, what would I do for the line

Thats just defining the players character, not required if you don’t need the players character.

1 Like

Yeah, but how would I get the humanoid then?

Player.Character.Humanoid is how you would get the Humanoid.

2 Likes

You really can’t access the player any other way, so using it would be useful. It doesn’t hurt your script if you include the parameters anyway.

playerWhoClicked is the Player object. When doing playerWhoClicked.Character.Humanoid, it will retrieve their Humanoid.

1 Like

Do you have any other questions or concerns? If not make sure to mark the post you feel was most helpful as the solution.

No questions. A lot of people helped though, so I’m can’t really mark all of them as the solution.

I’ve quoted all the help from the people I got in the original post.

Add a StringValue in the Thing that the object that is being clicked

ClickDetector.MouseClick:Connect(function(Player)
    script.Parent.StringValue = Player.Name
end)

then you could get the player name from any script!

Thanks, but I’ve already solved the problem.