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

Why can't I kill the player?

I cannot get the lava to kill my player! Any Ideas on how to fix it?

local lava = script.Parent

lava.Touched:Connect(function()
	game.Players.LocalPlayer.Humanoid.Health = 0
end)

2 answers

✓ Accepted answer

When using .Touched, one value is passed to the function hit which you can then use to check if the hit is a player.

Here's an (untested) example:

local lava = script.Parent

lava.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- check if the hit is a player
        hit.Parent.Humanoid.Humanoid.Health = 0 -- kill the player
    end
end)

1 comment

0

that doesn't check if hit is a player, it checks if hit is an NPC or a player

If its a normal script, it cannot find LocalPlayer, your best bet is to find the Humanoid instead with the touched function

1 comment

0

So how could I find the humanoid instead with the function?

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