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.
1 | function Clicked(Player) |
2 | Humanoid = Player.Character:FindFirstChild( "Humanoid" ) |
3 | if ( Humanoid ~ = nil ) then |
4 | Humanoid.Health = 0 |
5 | end |
6 | end |
7 |
8 | script.Parent.ClickDetector.MouseClick:Connect(Clicked) |
The proper event is MouseClick not Clicked and it returns the Player not the Character.
This should work
1 | function Clicked(plr) --Plr = Character |
2 | hum = plr.Parent:FindFirstChild( "Humanoid" ) |
3 | if (hum ~ = nil ) then |
4 | hum.Health = 0 |
5 | end |
6 | end |
7 | script.Parent.ClickDetector.Clicked:Connect(Clicked) |
I did look at it on the wiki, this is how it should be
1 | function Clicked(plr) --Plr = Character |
2 | hum = plr.Parent:FindFirstChild( "Humanoid" ) |
3 | if (hum ~ = nil ) then |
4 | hum.Health = 0 |
5 | else |
6 | print ( "No human" ) |
7 | end |
8 | end |
9 | script.Parent.MouseClick:connect(Clicked) |
Problem is it cant find a humanoid. How do I figure that out?