Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ 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.

4 comments

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.

0

Whoops sorry about the connect. It happens making up code on the spot.

0

And apparently I cant +1 you since some idiot randomly -1'ed me. Sorry :/

0

Nvm, figured it out.

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.