Easier way to handle variables?

I’ve never once used a ModuleScript before but want to try learning it. I often find myself rewriting tweens in my code and thought that I might be able to utilize a ModuleScript to make tweening things easier in my projects.

Basically there would be one server script which gets put into the object I want to tween and then there is a ModuleScript inside ServerStorage.

I’m currently working on the server script. I want it to be easy for me to edit all of the tween variables such as duration, easingStyle, easingDirection, etc.

Right now I have just a bunch of variables in the script that get passed as parameters through a function to the ModuleScript. Is this the easiest way to do this? Would just adding attributes to the part be easier? Or some other way?

Any ideas?

Server script:

local tweenModule = require(game:GetService("ServerStorage"):WaitForChild("TweenModule"))

local part = script.Parent

local easingStyle = "Linear"
local easingDirection = "Out"
local repeatCount = 0
local reverseTween = false
local delayTime = 3

local tweenType = "Position"
local distance = 20


local function tweenPart()
	tweenModule.TweenPart(part, easingStyle, easingDirection, repeatCount, reverse, delayTime, tweenType, distance)
end

part.Touched:Connect(tweenPart)

(I’m aware some properties of the tween are not included, I never finished adding all of them)

2 Likes

I think modulescripts are the best way to handle a lot of variables for different scripts, since they are all in one place and they do not have to be reiterated, as your problem presents.

However, you would want to place modulescripts inside ReplicatedStorage, since both the server and the client can immediately access it.

If you watch gnomecode’s video on modulescripts, you should get a really good understanding of how they work.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.