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

How to code lava so people can die?

Asked by 3 years ago
Edited 3 years ago

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)

1 answer

Log in to vote
1
Answered by 3 years ago

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.

0
You won't need line 4, if player then is enough Nguyenlegiahung 1091 — 3y
Ad

Answer this question