RE: How to construct a tween, i.e. what exactly goes inside it?

Continuation of an earlier post, I am wondering on the specifics of constructing a tween properly, this is what I made based off wiki info (btw its incorrect)

local ShopTween=TweenService:Create(plr.PlayerGui.Shop.Weapons, TweenInfo.new(nil, Enum.EasingStyle.Elastic,1.15), TweenSizeAndPosition(UDim2.new(0.515, 0,0.61, 0), UDim2.new(0.25, 0,0.2, 0))

In the exit button area Ill have it to where it detects until completed and proceed. but wiki isnt too helpful on how to construct it in its entirety

How I am trying to do it:
object, tweeninfo(parameters for style and time), tween pos and size for the designated object

Original Tween (done without local tween)

plr.PlayerGui.Shop.Weapons:TweenSizeAndPosition(UDim2.new(0.515, 0,0.61, 0), UDim2.new(0.25, 0,0.2, 0),nil,Enum.EasingStyle.Elastic,1.15)

I’m not really sure what I could add that the API reference doesn’t show already: Tween | Roblox Creator Documentation , Tween | Roblox Creator Documentation ,
GuiObject | Roblox Creator Documentation

In essence tweens are constructed like this:

TweenService:Create(part, tweenInfo, position)

You can make a tween size and position like this:

GUI:TweenSizeAndPosition(Size, Position)

You can list any additional information like easing style/direction after the position.

the thing about it is why does the following:

TweenService:Create(part, tweenInfo, position)

only have position to tween? I think I can manage without but its kinda weird why theres only position and not size (also I am referencing a gui object I hope it works this way) Ill test it sometime in the next few days.

tween info is a local to be created which can contain the following (I assume I can set things to nil i.e. easing style):

local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)

This is bad practice, and will result in memory consumption.

But that’s literally one of the ways you are given to tween…?

Just because it’s an option doesn’t mean it’s a good one.
I’m speaking from experience. If that doesn’t seem valid, then let data overrule anecdotes.

What would be the alternative when using GUI:TweenSizeandPosition? I’ve only ever seen it done like that (including on the API reference).

TweenService. TweenService can tween most properties, including those on GUI.

Right, which is why I provided info as to how to create tweens regularly, but the OP seemed confused between the two.

You can tween size as well. I just gave an example of a property you could tween.

I think I may have found a solution:

for the position area i put a local called “goal”

local Goal = {Size = Udim2.new(0.515, 0,0.61, 0),Position=UDim2.new(0.25, 0,0.2, 0)}
local tweenInfo = TweenInfo.new(
	1.15, -- Time
	Enum.EasingStyle.Elastic, -- EasingStyle
	nil, -- EasingDirection
	nil, -- RepeatCount (when less than zero the tween will loop indefinitely)
	nil, -- Reverses (tween will reverse once reaching it's goal)
	nil -- DelayTime
)

so:

local ShopTween=TweenService(plr.PlayerGui.Shop.Weapons,TweenInfo,Goal)

some time later in script:

ShopTween:Play()

I will test it out when I have time.

1 Like

This is why it’s always a good idea to read documentation. The entire composition is explained on the Create function’s page. There are three arguments involved:

  • The instance you are tweening.
  • A TweenInfo object describing how the tween should look.
  • A table representing what the properties should be when the tween finishes.

Put those together and you have a tween. The last post you made resolves your question - to tween both with TweenService you’d have both a Size and a Position goal.

TweenService:Create(Weapons, TweenInfo, {
    Size = UDim2,
    Position = UDim2,
})
1 Like