Help with TweenSizeAndPosition

So I am REALLY new to UI Vectors, and I am trying to tween a ViewPortFrame to close just like a retro window would. My problem is:


It is not how I want it to close. You know it too.
My code:

local SizeEnd1 = UDim2.new(0.335,0,0.002,0)
local SizeEnd2 = UDim2.new(0, 0,0.002, 0)
local PosEnd = UDim2.new(0.321, 0,0.229, 0)



wait(20)
script.Parent:TweenSizeAndPosition(SizeEnd1, PosEnd, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.2)
wait(0.4)
script.Parent:TweenSizeAndPosition(SizeEnd2,PosEnd, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.2)

PosEnd is the frame’s current position.

You need to remove UI Corner i guess. You can do it in script.

No, the UICorner is not my problem, the tween is.
I want it to make the tween at the same position, but it’s moving.

Can you show us an example of what you want? (video)

Here:


Sorry for lag, potato pc

Set the anchorpoint of the UI and reposition the UI then try it again

Well that works but what is the Vector I should use? I have tried Vector2.new(0.5, 0.5) but it is not in the middle

UIs dont use Vector2 they use UDim2. Try doing UDim2.new(.5,0,.5,0)

It worked with Vectors too. Just as DevHub says. But what’s the middle point ?

if you were to use UDim2 with .5 as the scale for both X and Y it would get the exact middle point of the UI and i wouldnt know how to do it with Vectors as i never use Vectors with UI you could also use UDim2.FromScale

Getting an error, I knew it…

Players.octav20071.PlayerGui.SurfaceGui.ViewportFrame.Script:6: invalid argument #3 (Vector2 expected, got UDim2)

hm. let me go do some testing with Vector2 to see if i can help you

1 Like

use that for the AnchorPoint but for the position of the UI do UDim2.new(.5,0,.5,0)

The feedback was the UI sliding to the right and closing. Nope.


I have changed it with the TweenSize function, but the thing is, the anchor point!

Question. Is the UI precreated in studio or created midgame

It is created in studio. Setting the anchor point to 0,0 in script doesn’t change anything

you need to set the anchor point to .5,.5 and the anchor point will change to the middle of the UI object and then change the position to .5,0,.5,0 so it will go to the middle of the UI object it is parented to

I mean, that works 50%, the frame spawns in other direction than the one needed, but tweens how it should… Maybe it’s the anchor point?


You want the one on the RIGHT correct?

Yes, yes! I want that one! How could I achieve it?