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

Adding wait, glitches the script, in giving an error for the next line of code??

Asked by 4 years ago
Edited 4 years ago

So I have this script, thats a part of my sword. The damage and animation are a little off, so I wanted to add a wait to the damage part. I added it, then it gives an error, for the next line of code. I take it away, and it works perfectly fine. I have no idea why, this has never happened to me before. This is the error 19:52:34.046 - Players.Wilbyte.Backpack.Stick.Script:16: attempt to index field 'Parent' (a nil value). Code:

CanDamage = true
script.Parent.Handle.Touched:Connect(function(p)
if CanDamage == true then
    if p.parent:FindFirstChild("Zombie") then
        wait(.2)
p.Parent.Zombie:TakeDamage(20)
CanDamage = false
    end
    end
end)

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

the wait(.2) you added isn't the problem. The problem is that in line 4, Parent isn't capitalised. it should be if p.Parent:FindFirstChild("Zombie") then instead

0
Thanks, but its still glitching zandefear4 90 — 4y
Ad

Answer this question