Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

Thanks, but its still glitching

This discussion is preserved as it was. New answers, comments, and votes are closed.