Adding to a Script Source

I’m creating a Tween editor plugin and i use a ModuleScript for information about keyframes.

I’m not sure if there is a way to add a table to a ModuleScripts’ source without deleting what was there
and change variable info like Position and Time.

I haven’t tried anything because i don’t know how to Add to a ModuleScript at all.

What i want to achieve in ModuleScript
local Tweens = {
	["Tween1"] = {
		DefaultPos = UDim2.new(),
		TweenPos = UDim2.new(),
		Length = 1,
		EasingStyle = "Quad",
	},
	["Tween2"] = {
		DefaultPos = UDim2.new(),
		TweenPos = UDim2.new(),
		Length = 3,
		EasingStyle = "Sine",
	},
}

return Tweens
Plugin Script
defaultPos.MouseButton1Up:Connect(function()
	local Selected = SelectionService:Get()[1]
	if Selected then
		local Animator = QuickFunc.GetAnimator(Selected)
		Animator.Source = Animator.Source:gsub("DefaultPos = UDim2.new()[^\n]*\n", ("DefaultPos = UDim2.new(%s, %s, %s, %s)\n"):format(Selected.Position.X.Scale, Selected.Position.X.Offset, Selected.Position.Y.Scale, Selected.Position.Y.Offset))
		print("Success", "Def pos")
	end
end)

tweenPos.MouseButton1Up:Connect(function()
	local Selected = SelectionService:Get()[1]
	if Selected then
		local Animator = QuickFunc.GetAnimator(Selected)
		
		Animator.Source = Animator.Source:gsub("TweenPos = UDim2.new()[^\n]*\n", ("TweenPos = UDim2.new(%s, %s, %s, %s)\n"):format(Selected.Position.X.Scale, Selected.Position.X.Offset, Selected.Position.Y.Scale, Selected.Position.Y.Offset))
		print("Success", "Out pos")
	end
end)

Hoping someone can help me in the right direction or give me some info on how to go about adding to a ModuleScripts’ source. Thank you.

1 Like

You can use a module function to add an index to the table.

Pesudocode:

-- Module
Tweens.addTable = function(key, table)
     Tweens[key] = table
end
-- Server
QuickFunc.addTable("Tween3", Animator.Source)
1 Like

Change the EasingStyle’s to Enums, or else they won’t change

1 Like

Sorry, But does the Module part go in Animator or QuickFunc?

QuickFunc Module

–// Vars
local module = {}

–// Functions

module.GetAnimator = function(obj)
	local ModuleScript = obj:FindFirstChild("Animator")
	
	if ModuleScript then
		return ModuleScript
	else
		local _ModuleScript = script.Parent.Animator:Clone()
		_ModuleScript.Parent = obj
		return _ModuleScript
	end
end

return module