RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:06am
#1
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
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:09am
#3
Yes, it’s inside the part.
I want it when the click detector is clicked.
lluckvy
(aaron)
March 10, 2021, 4:09am
#4
-- 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
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:11am
#6
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
lluckvy
(aaron)
March 10, 2021, 4:12am
#8
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
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:13am
#10
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
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:14am
#12
Yeah, but how would I get the humanoid then?
Player.Character.Humanoid
is how you would get the Humanoid.
2 Likes
lluckvy
(aaron)
March 10, 2021, 4:15am
#14
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.
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:17am
#16
No questions. A lot of people helped though, so I’m can’t really mark all of them as the solution.
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 4:29am
#17
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!
RipPBB_TUD
(MetatablesOnTop)
March 10, 2021, 7:20pm
#19
Thanks, but I’ve already solved the problem.