How to kill a player through a Proximity Prompt?

I’m trying to make a proximity prompt that kills a player once it is activated. Here’s what I have:

part.ProximityPrompt.Triggered:Connect(function(player)
      player:WaitForChild("Humanoid").Health = 0
end)

I might have tried to find the “Humanoid” wrong, but I’m not too sure how else to find it.

When you activate a ProximityPrompt, it gives you their player instead of their character. To find the humanoid, you have to get their character and see if it exists, then find the humanoid (and check if it exists). If you get through all those checks, you can damage the humanoid.

part.ProximityPrompt.Triggered:Connect(function(player)
	local char = player.Character
	local hum = char and char:FindFirstChild("Humanoid") -- If the character exists, try to find its humanoid and put it in this variable.

	if hum then
		hum.Health = 0
	end
end)
2 Likes

Try :TakeDamage
Setting health to 0 is kinda wonky.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.