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)
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)
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)
If its a normal script, it cannot find LocalPlayer, your best bet is to find the Humanoid instead with the touched function
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.
1 comment
that doesn't check if hit is a player, it checks if hit is an NPC or a player