How do i change the lenght of a tween in a function?

Hello there,
im trying to customize this tween function so when i tween something using it i could customize the length of the tween:

function:

local function tween(instance, properties, info)
	info = info or TweenInfo.new()
	local tweenObject = game:GetService("TweenService"):Create(instance, info, properties)
	tweenObject:Play()
	return tweenObject
end

Calling the function:

tween(button:WaitForChild("area"), {Size = UDim2.new(0.483, 0,0.384, 0)})

my goal is to add something like a number to be the new length of the tween instead of the default one
example what i want:

tween(button:WaitForChild("area"), {Size = UDim2.new(0.483, 0,0.384, 0)}, length  = 3)

i tried changing the Tweeninfo.new() but failed, thanks for reading!

The length is the first argument of TweenInfo.

TweenInfo.new(
1, -- length (float)
-- easing style (EasingStyle)
-- easing direction (EasingDirection)
-- repeat count (int)
-- reverse on repeat (bool)
-- delay before repeat (float)
)

Oh, if i insert this into the function will i be in need to add other stuff inside the TweenInfo like easing style of easing direction etc…

You can if you want, but all arguments of TweenInfo have default values. The values can be found here.

Oh okay, i tried doing this:

	tween(button:WaitForChild("area"), {Size = UDim2.new(0.747, 0,0.384, 0)},{
	1,
	})

Screenshot 2023-01-17 155735
it resulted with an error

Since this is the function

local function tween(instance, properties, info)
	info = info or TweenInfo.new() --it should replace this info with what i entered and not create a new tweeninfo
	local tweenObject = game:GetService("TweenService"):Create(instance, info, properties)
	tweenObject:Play()
	return tweenObject
end

You would need to pass TweenInfo, and not an array. I saw you passed {1} instead!


its not allowing me to, and when i remove the “,” it still does not work

tween(button:WaitForChild("area"), {Size = UDim2.new(0.747, 0,0.384, 0)}, TweenInfo.new(1))

It worked thank you! {HASTOBE30CHARACTERS}

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