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

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.