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 10 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
10 years ago
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.

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 — 10y
0
Whoops sorry about the connect. It happens making up code on the spot. jav2612 180 — 10y
0
And apparently I cant +1 you since some idiot randomly -1'ed me. Sorry :/ Orlando777 315 — 10y
0
Nvm, figured it out. Orlando777 315 — 10y
Ad
Log in to vote
2
Answered by 10 years ago

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)
0
You forgot a end and Clicked isn't a part of ClickDetector... Orlando777 315 — 10y
0
It's an event of it. Look on the wiki RolandStudio 115 — 10y
0
Read my answer below. Orlando777 315 — 10y
0
Opps Silly Mistake sorry my brain is rusty after answering a lot RolandStudio 115 — 10y
Log in to vote
-1
Answered by 10 years ago

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?

Answer this question