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 8 years ago

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

01local removeHealth = false
02 
03script.Parent.Touched:connect(function(otherPart)
04    local character = otherPart.Parent
05    local humanoid = character:FindFirstChild("Humanoid")
06 
07    if humanoid then
08        removeHealth = true
09    end
10 
11    while removeHealth == true do
12        wait(1)
13        local CurrentHealth = humanoid.Health
14        local HealthToRemove = 12
15 
View all 24 lines...

Any help?

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

1 answer

Log in to vote
0
Answered by 8 years ago

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

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

Answer this question