--This works, also playercharacter is defined.
if playercharacter:FindFirstChild("Animate"):FindFirstChild("run") then playercharacter:FindFirstChild("Animate"):FindFirstChild("run"):Destroy() end

--However this doesn't work
if playercharacter:FindFirstChild("Animate"):FindFirstChild("run") then playercharacter:FindFirstChild("Animate"):Destroy() end

Can someone explain why the second one doesn't work? I have to remove the ":FindFirstChild("run")" before the "then" for it to work, but why? It finds "Animate" anyway, so what's stopping it from destroying it?

10 comments

0

Your code works perfectly fine for me, both of them. Not sure why it's not working for you, maybe an interfering script?

0

I have no idea. It only happens half the times I run the game. I get an error saying attempt to index nil value.

0

That's because the script didn't find "Animate" when it ran. Therefore FindFirstChild returned nil. Add an if statement to check if Animate exists.

0

Yes but how come it finds it in the first code?

0

I can also see them in explorer. They get destroyed, but I still get the error and the code afterwards doesn't work. This shows that it found it.

0

Did you do what incapaz said? If so what changed?

0

I didn't do it because the script finds 'Animate'. I know this because it does get destroyed.

0

whats the point of typing all that twice anyway? It would be a lot easier to just make it a variable then do if variable then variable:Destroy() end

0

capital r? in run? idk

0

Nope.