Refactored luaTask() based on script type