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

Can someone explain why this doesn't work? (Short code)

Asked by
LawlR 182
5 years ago
--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?

0
Your code works perfectly fine for me, both of them. Not sure why it's not working for you, maybe an interfering script? MythicalShade 420 — 5y
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. LawlR 182 — 5y
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. User#19524 175 — 5y
0
Yes but how come it finds it in the first code? LawlR 182 — 5y
View all comments (6 more)
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. LawlR 182 — 5y
0
Did you do what incapaz said? If so what changed? MythicalShade 420 — 5y
0
I didn't do it because the script finds 'Animate'. I know this because it does get destroyed. LawlR 182 — 5y
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 Vulkarin 581 — 5y
0
capital r? in run? idk greatneil80 2647 — 5y
0
Nope. LawlR 182 — 5y

Answer this question