Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

How do you get the Players Character from a Part he/she clicked?

Asked by 11 years ago

I have a Part with a Click Detector and a script that will kill the player once it is clicked and the script can find the character. It could be clicked at INF distance so Local Player wont work.

3 answers

Log in to vote
4
Answered by
jav2612 180
11 years ago
1function Clicked(Player)
2    Humanoid = Player.Character:FindFirstChild("Humanoid")
3    if ( Humanoid ~= nil) then
4        Humanoid.Health = 0
5    end
6end
7 
8script.Parent.ClickDetector.MouseClick:Connect(Clicked)

The proper event is MouseClick not Clicked and it returns the Player not the Character.

0
Wow i didn't see what it returned...Lol thanks. BTW Tested it :Connect is with a lower-case C. Ill +1 you both :) Thanks again. Orlando777 315 — 11y
0
Whoops sorry about the connect. It happens making up code on the spot. jav2612 180 — 11y
0
And apparently I cant +1 you since some idiot randomly -1'ed me. Sorry :/ Orlando777 315 — 11y
0
Nvm, figured it out. Orlando777 315 — 11y
Ad
Log in to vote
2
Answered by 11 years ago

This should work

1function Clicked(plr) --Plr = Character
2hum = plr.Parent:FindFirstChild("Humanoid")
3if (hum ~= nil) then
4hum.Health = 0
5end
6end
7script.Parent.ClickDetector.Clicked:Connect(Clicked)
0
You forgot a end and Clicked isn't a part of ClickDetector... Orlando777 315 — 11y
0
It's an event of it. Look on the wiki RolandStudio 115 — 11y
0
Read my answer below. Orlando777 315 — 11y
0
Opps Silly Mistake sorry my brain is rusty after answering a lot RolandStudio 115 — 11y
Log in to vote
-1
Answered by 11 years ago

I did look at it on the wiki, this is how it should be

1function Clicked(plr) --Plr = Character
2hum = plr.Parent:FindFirstChild("Humanoid")
3if (hum ~= nil) then
4hum.Health = 0
5else
6    print("No human")
7end
8end
9script.Parent.MouseClick:connect(Clicked)

Problem is it cant find a humanoid. How do I figure that out?

Answer this question