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

Why is the TouchEnded function doing this error?

Asked by 6 years ago
Edited 6 years ago

Hello, I'm making a model with Touched And TouchEnded to set a value to true or false, then it fire projectiles, but everytime that the enemy dies and fire the TouchEnded function, this happens:

17:52:29.469 - Workspace.Model.Touch:9: attempt to index field 'Parent' (a nil value)

Script:

function OnTouch(Hit)
   local Check = Hit.Parent:FindFirstChild("Zombie")
     if Check then
    script.Parent.Value.Value = true
end
end

function OnTouchEnded(Hit)
    local Check = Hit.Parent:FindFirstChild("Zombie")
      if Check  then
    script.Parent.Value.Value = false
    end
end

script.Parent.Part1.Touched:connect(OnTouch)
script.Parent.Part1.TouchEnded:connect(OnTouchEnded)

If theres any way to solve it, Please tell me. Thanks!

PS: The enemy gets removed when her Died function fires, then that happens.

0
Could it be that on line 9 it checks for "zombie" but zombie doesn't exist anymore so it gets a nil value? noammao 294 — 6y
0
Ya i think thats it, i just don't know how to fix that way Joozinho 0 — 6y
0
use an if statement instead of assigning it to variable first. Because if it doesn't exist it will just throw an error Legoman654 100 — 6y

Answer this question