So following my first question, I did some scripting tutorials and leaned a bit of scripting. What I'm trying to achieve here is that when people click the part, they instantly die. I have added the script and click detector inside the part. My code is below.
01 | local part = script.Parent |
02 |
03 | local function kill(otherpart) |
04 | local partparent = otherpart.parent |
05 | local humanoid = partparent:FindFirstChild( "Humanoid" ) |
06 | if humanoid then |
07 | humanoid.Health = 0 |
08 | end |
09 | end |
10 |
11 |
12 | part.MouseClick:connect(kill) |
Please tell me where I went wrong. Thank you!
Hey the mistake you made was that "otherpart" is not equal to a part of the player but is equal to game.Players[playername] meaning that otherpart.Parent will be equal to game.Players. Try this script i made that should work :)
1 | local part = script.Parent |
2 |
3 | part.ClickDetector.MouseClick:Connect( function (plr) -- An event that activates a function when the part is clicked. |
4 | local humanoid = plr.Character:FindFirstChild( "Humanoid" ) -- Finds the players humanoid |
5 | if humanoid then -- Checks if the player has a humanoid. |
6 | humanoid.Health = 0 -- Kills the player |
7 | end |
8 | end ) |