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 5 years ago
Edited 5 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:

01CanDamage = true
02script.Parent.Handle.Touched:Connect(function(p)
03if CanDamage == true then
04    if p.parent:FindFirstChild("Zombie") then
05        wait(.2)
06p.Parent.Zombie:TakeDamage(20)
07CanDamage = false
08    end
09    end
10end)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 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 — 5y
Ad

Answer this question