Turning code into module

Good day,

I am just learning Lua and have this server code below which plays a tween for many parts, instead of having the same code on all parts can the code be put in a module and called?

wait(5) -- Wait for things to load

local Speed = 2  		-- Speed
local MoveDist = -10  	-- Distance
local ActivateDist = 15 -- Tween Activation Distance
local running = false	-- Is the tween running

local ts = require(game.ReplicatedStorage.Modules:WaitForChild("TweenServicePlus"))
local tween = ts:Construct(script.Parent, TweenInfo.new(Speed, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, -1, true, 0), { Position = script.Parent.Position + Vector3.new(MoveDist, 0, 0)}, .4, false)

while true do
	for _, player in pairs(game.Players:GetPlayers()) do
		local playerMag = player:DistanceFromCharacter(Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z))
	
		if playerMag < ActivateDist and running == false then
			running = true
			tween:Play()
		elseif playerMag < ActivateDist + 1 and running == true then
			running = false
			tween:Pause()
		end
	end
	wait()
end

Yes, You can have it in a module and return a function sort of like this:

function tween(part)
    --tween the received part
end

return tween

You would call it by

local tween = require(--[[modulepath]])
local part = --part path
tween(part)