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

Why can't I kill the player?

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
1
Answered by
0x5y 105
1 year ago

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)
0
that doesn't check if hit is a player, it checks if hit is an NPC or a player T3_MasterGamer 2189 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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

0
So how could I find the humanoid instead with the function? Puppy_lovertheawsome 84 — 1y

Answer this question