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