Premise: I have a sword. When I hold right click, a localscript will detect mouse.Button2Down and fire a remote event which will be caught by a function we can call function1 in a serverscript. in function1, i create a looped animation of me holding my arm in place, and when mouse.Button2Up I want to stop the animation.
Trouble is, I cannot access local variables from another function.
for a simple example, I already tried and failed to do this: local animation
function
animation = new instance of animation
animation:Play()
end
function
animation:Stop()
end
...Such that the variable is created outside both functions, then defined in the first one, and from there the second function can use the animation variable to fetch that animation i created in function1. But it didn't work.
I did some more research and someone told me I could use return instead. I looked everywhere for how to use return, and somehow the internet never fails to give me a practical example of return that's understandable to someone who hasnt been scripting for decades. in addition, the examples they gave at all were normal functions with no parameters, while my function1 did have parameters and player as an automatic parameter (because this function1 caught the remote event fired in the localscript far aforesaid)
Does anyone understand what I just said? In short, since nil variables aren't working for me, I was told I could use return, but I do not completely know the syntax, and the internet won't give me one. Can one of you present me with the solution?

1 comment
There is a fault in the AnimationTrack onloading, you'd be raised an "attempt to index nil" error if there was an issue with the variable scope.