#Help with understanding this code

1 messages · Page 1 of 1 (latest)

wraith yoke
#

this code word perfectly fine but it keeps giving me an error stating: ServerScriptService.Lava:9: attempt to index nil with 'Health'

local mg = game.Workspace:WaitForChild("Maingame")
local lavas = mg:WaitForChild("Lava")

for _, lava in pairs(lavas:GetChildren()) do
lava.Touched:Connect(function(otherpart)
local touched = otherpart.Parent:FindFirstChild("Touched")
local humanoid = otherpart.Parent:FindFirstChild("Humanoid")

            humanoid.Health = 0                
    
end)

end

mystic orchid
#

are u trying to kill players?

obtuse parcel
#

check if the parent of the part that was hit

#

has a humanoid

mystic orchid
#
local mg = game.Workspace:WaitForChild("Maingame")
local lavas = mg:WaitForChild("Lava")

for _, lava in pairs(lavas:GetChildren()) do
    lava.Touched:Connect(function(otherpart)
        local character = otherpart.Parent
        local humanoid = character and character:FindFirstChild("Humanoid")

        if humanoid then
            humanoid.Health = 0
        end
    end)
end
mystic orchid
obtuse parcel
mystic orchid
wraith yoke
#

it's still giving me an error

wraith yoke
#

wait

#

nvm

mystic orchid
#

knew it baldy

wraith yoke
#

so bsiclaly I only needed to put an if statement?

mystic orchid
wraith yoke
#

alright

#

thank you bro