So I have a function that will use tweenservice on a modulescript
This is what I usually do
local module = {}
function module.FunctionName()
local ts = game:GetService("TweenService")
local module = require(modulename)
end
return module
The thing I want to know is should calling services and requiring functions be in the function or someplace else? And if it should be someplace else where would it be?
If you’re requiring modules and getting services in a function, that means that every time you call that function, then it’s gonna require those modules and get those services everytime.
It would be more performant to put it outside of a function to only require those modules and get those services that way they only get required once (since you don’t need to get them again)
I would say that you should put these near the top of your script so it’s easy to see what things youve already defined. That way you don’t have to look for them
Because your definition of module is being replaced / overwritten by the new definition for module
look:
local module = {}
is being changed to
local module = require(modulename)
since the variables are the same name
And is when you try to define a function, it doesnt define it under module = {} but instead it’s defined under the module you’re requiring module = require(modulename)