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.
✓ ANSWER ACCEPTED
How do you get the Players Character from a Part he/she clicked?
3 answers
✓ Accepted answer
function Clicked(Player)
Humanoid = Player.Character:FindFirstChild("Humanoid")
if ( Humanoid ~= nil) then
Humanoid.Health = 0
end
end
script.Parent.ClickDetector.MouseClick:Connect(Clicked)
The proper event is MouseClick not Clicked and it returns the Player not the Character.
This should work
function Clicked(plr) --Plr = Character
hum = plr.Parent:FindFirstChild("Humanoid")
if (hum ~= nil) then
hum.Health = 0
end
end
script.Parent.ClickDetector.Clicked:Connect(Clicked)
4 comments
0
You forgot a end and Clicked isn't a part of ClickDetector...
0
It's an event of it. Look on the wiki
0
Read my answer below.
0
Opps Silly Mistake sorry my brain is rusty after answering a lot
I did look at it on the wiki, this is how it should be
function Clicked(plr) --Plr = Character
hum = plr.Parent:FindFirstChild("Humanoid")
if (hum ~= nil) then
hum.Health = 0
else
print("No human")
end
end
script.Parent.MouseClick:connect(Clicked)
Problem is it cant find a humanoid. How do I figure that out?
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
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.
Whoops sorry about the connect. It happens making up code on the spot.
And apparently I cant +1 you since some idiot randomly -1'ed me. Sorry :/
Nvm, figured it out.