I am trying code lava, is this right code?
script.Parent.Touched:Connect(function(hit) local character = hit.Parent local human = character:FindFirstChild("Humanoid") local player = game.Players:GetPlayerFromCharacter(character) if player and human.Health > 0 then human.Health = 0 end end)
This is pretty easy. All you have to do is make a script in the part you want to kill the player. Then insert this
script.Parent.Touched:Connect(function(hit) local character = hit.Parent local human = character:FindFirstChild("Humanoid") local player = game.Players:GetPlayerFromCharacter(character) if player and human.Health > 0 then human.Health = 0 end end)
So what this script does is. First, we connected the part with .Touched event.
The .Touched event will return us the part that touched the lava part.
Once we have what touched the lava part we need to check if the part is the player, so we get the character by getting the Parent of the part, then we use character:FindFirstChild("Humanoid") to get the Humanoid that contains the Health of the character and we get game.Players:GetPlayerFromCharacter(character) to get the player from the character.
Now that we have all we need we do an if statement to check if its a player and its not dead then kill the player by changing its health to 0.