Tween Editor Problem

I’ve been making my own Tween editor Gui for my own convenience.
My editor uses a similar way of getting a Default position and then a Tweened position like the TweenSequence Editor.

When i click Default pos button it’ll replace “local DefaultPos” with “local DefaultPos = UDim2.new(POS)”

Button Script
defaultPos.MouseButton1Up:Connect(function()
	local Selected = SelectionService:Get()[1]
	if Selected then
		local Animator = QuickFunc.GetAnimator(Selected)
		Animator.Source = Animator.Source:gsub("local DefaultPos", "local DefaultPos = UDim2.new("..Selected.Position.X.Scale ..", ".. Selected.Position.X.Offset ..", ".. Selected.Position.Y.Scale ..", ".. Selected.Position.Y.Offset ..")")
		print("Success", "Def pos")
	end
end)
QuickFunc Script
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
Animator Script
local KeyFrame = {
	Play = function()
		local DefaultPos
		local OutPos
		local Length
		local EasingStyle = "Quad"
		
		script.Parent.Position = DefaultPos
		script.Parent:TweenPosition(OutPos, "Out", EasingStyle, Length)
		wait(Length + 1)
		script.Parent.Position = DefaultPos
	end
}

return KeyFrame

If i want to update the Default pos it’s doing this:

Weird script
local KeyFrame = {
	Play = function()
		local DefaultPos = UDim2.new(0.89415556192398, 0, 0.45788159966469, 0) = UDim2.new(0.9539806842804, 0, 0.45788159966469, 0)
		local OutPos
		local Length
		local EasingStyle = "Quad"
		
		script.Parent.Position = DefaultPos
		script.Parent:TweenPosition(OutPos, "Out", EasingStyle, Length)
		wait(Length + 1)
		script.Parent.Position = DefaultPos
	end
}

return KeyFrame

I’m hoping someone can guide me to fixing this or point out something i should use instead of maybe gsub.
Thank you very much.

You are replacing the locale defaultPos value, without replacing the = UDim2.new(0.89415556192398, 0, 0.45788159966469, 0), thus you get the weird script.

I’d include the = UDim2.new(0.89415556192398, 0, 0.45788159966469, 0) (or any value until the next line), via string patterns for the value to replace. Somehting like this:

Animator.Source = Animator.Source:gsub("local DefaultPos.+\n", ("local 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));

This works, However it deletes everything after it except return KeyFrame.

Script
local KeyFrame = {
	Play = function()
		local DefaultPos = UDim2.new(0.89415556192398, 0, 0.48290246725082, 0);
return KeyFrame

Is there a way to stop it from deleting that?

My bad, I meant local DefaultPos[^\n]*\n. Lua string patterns unlike RegEx includes lines breaks for the . patern for some reason, try changing .+\n with [^\n]*\n in my script.

Animator.Source = Animator.Source:gsub("local DefaultPos[^\n]*\n", ("local 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));

I appreciate the help. i cannot thank you enough.
I’ve not used String patterns before and i haven’t found a tutorial on these types.

Again, Thank you.