Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

im getting "Player is not a valid member of Player "Players.Wolverine132416" error?

Asked by 1 year ago

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)

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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.

local ClickDetector = script.Parent

function onClicked(player)
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if humanoid then
        -- humanoid.Die() ?
        -- There is no such method "Die". Instead, set the humanoid's health to 0.
        humanoid.Health = 0
    end 
end

ClickDetector.MouseClick:Connect(onClicked)
Ad

Answer this question