so im trying to make it where when you click the part you die but it keeps saying players inst a valide meber of players heres the code:
local ClickDetector = script.Parent
function onClicked(mouse) local player = mouse.Player local humanoid = player.Character:FindFirstChild("Humanoid") if humanoid then humanoid.Die() end end
ClickDetector.MouseClick:Connect(onClicked)
Player is not a valid member of Player "Players.Wolverine132416"
The error means you are attempting to find a child named "Player" inside your player object. You do not need to find the player, as the MouseClick
event already returns the player who clicked it.
01 | local ClickDetector = script.Parent |
02 |
03 | function onClicked(player) |
04 | local humanoid = player.Character:FindFirstChild( "Humanoid" ) |
05 | if humanoid then |
06 | -- humanoid.Die() ? |
07 | -- There is no such method "Die". Instead, set the humanoid's health to 0. |
08 | humanoid.Health = 0 |
09 | end |
10 | end |
11 |
12 | ClickDetector.MouseClick:Connect(onClicked) |