The function should be in a definition type script.
Definition scripts are run at game launch, thus they are good for declaring functions & variables.
Execution scripts (definition unticked) will only work when you manually call the script via the call script action part. These should only be used when functions aren't needed, & even then should only really be used if the script you write has a lot of lines of code or you want to call it multiple times throughout the game.
For the most part you should only really be using definition type scripts & execute a script action parts.
Now in regards to what you wrote:
setAnimFrames("Animation4", 2, 12)
What you are doing here is forcing animation "Animation4" to loop between frames 2 & 12. The animation needs to be set to loop infinitely otherwise it won't work, as the animation will automatically end & hide when it reaches the final frame. In regards to forcing an animation to be locked to a single frame you just need to enter the same frame number into the function twice - taking into account that animations start from frame 1 & not 0 when it comes to Lua script...
setAnimFrames("example", 12, 12) -- force animation "example" to loop frame 12