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

attempt to index local 'humanoid' (a nil value) ???

Asked by 7 years ago

attempt to index local 'humanoid' (a nil value)

local removeHealth = false

script.Parent.Touched:connect(function(otherPart)
    local character = otherPart.Parent
    local humanoid = character:FindFirstChild("Humanoid")

    if humanoid then
        removeHealth = true
    end

    while removeHealth == true do
        wait(1)
        local CurrentHealth = humanoid.Health
        local HealthToRemove = 12

        CurrentHealth = CurrentHealth.Value - HealthToRemove
    end

    script.Parent.TouchEnded:connect(function(otherPart)
        if humanoid then
            removeHealth = false
        end
    end)
end)

Any help?

0
Is this error occurring after you're killed, before, or during? M39a9am3R 3210 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

You need to 'end' your script if the toucher is not a humanoid.

if not humanoid then
return end

elseif humanoid then
removeHealth = true
end
0
Not sure if this is gonna fix it, but most of times I had this problem. VladimVladim 78 — 7y
0
Now it says: 'end' expected (to close 'function' at line 3) near 'elseif' Dinakzy 6 — 7y
0
Place another 'end' after end on line 6 VladimVladim 78 — 7y
Ad

Answer this question