TweenPosition doesn't work

Greetings,

I want to make my gui move smoother. But the animation doesn’t work? Simply the GUI just pops up on the screen, nothing else, no animation. Please help

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("FunZone"):WaitForChild("Transition")
local frame = script.Parent

Event.OnClientEvent:Connect(function(timer)
	frame.Visible = true
	frame:TweenPosition(UDim2.new(0, 0, 0, 0),"In","Circular",1)
	wait(timer)
	frame:TweenPosition(UDim2.new(1, 0, 0, 0),"In","Circular",1)
	frame.Visible = false
end)

Could you show me where the event is being fired?

Make sure to originally move the Frame to another location. If it’s already set to (0, 0, 0, 0) then it will appear to not change. So, to fix this, first set the position outside of the viewport. For example,

Event.OnClientEvent:Connect(function(timer)
    frame.Position = UDim2.new(1, 0, 0, 0)
    ...
end)

There is no problem with the event, I said that the GUI pops up with no animation.

its already set to 1,0,0,0 so :confused:

image

Are you sure you’re tweening the correct object?

We can’t really figure out what’s going on without sufficient information.

I admit it, its my first time using TweenPosition, those are the properties and the path:

image

The local script inside has the code and the frame is the “Transition”. What I’m trying to make is the frame to come from the right side of the screen to the middle, wait on that timer value and then go back.

Well, if you want the Frame to smoothly transition out, you need to wait and then make the Frame invisible.

Event.OnClientEvent:Connect(function(timer)
	frame.Visible = true
	frame:TweenPosition(UDim2.new(0, 0, 0, 0),"In","Circular",1)
	wait(timer)
	frame:TweenPosition(UDim2.new(1, 0, 0, 0),"In","Circular",1)
        wait(1) -- wait for the tween to finish
	frame.Visible = false
end)

I’m not so sure why it might not be transitioning in though…

You need to use Enum not text where you try to tween like Enum.EasingStyle.Circular i can’t text it now and i don’t remeber names of this Enums, sorry i will try to help you soon.

1 Like

Ensure that the OnClientEvent event is being fired properly by the server-side code that is responsible for triggering it. If the event is not being fired, then the client-side code will not execute.

In your current script, the issue might be due to the fact that the GUI is being hidden immediately after the second Tween finishes. To make sure the second Tween completes before the GUI is hidden, you can use the TweenFinished event. Here’s the updated script:

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("FunZone"):WaitForChild("Transition")
local frame = script.Parent

Event.OnClientEvent:Connect(function(timer)
	frame.Visible = true
	local tweenIn = frame:TweenPosition(UDim2.new(0, 0, 0, 0), "In", "Circular", 1, false)
	tweenIn.Completed:Wait() -- Wait for the tween to finish
	
	wait(timer)
	
	local tweenOut = frame:TweenPosition(UDim2.new(1, 0, 0, 0), "In", "Circular", 1, false)
	tweenOut.Completed:Wait() -- Wait for the tween to finish
	
	frame.Visible = false
end)

In this script, I’ve added the false argument to the :TweenPosition() function calls to disable the automatic play. This allows you to wait for the TweenFinished event to make sure the tweens complete before proceeding with the script.

Now, the GUI should smoothly slide in and out according to the timer value.


:confused: now this happens

Oh yea and also the animation does not happen (the screen appeared like usual without animation, just popped up).

Just please read the comments and you can clearly see that the event is working fine.

It’s because circular isn’t an easing style that works with TweenPosition.

3 Likes

The Completed:Wait() event doesn’t exist for these types of tweens. It only returns a boolean value.

You can only make tweens that have it with TweenService:Create(...) , such as:

local tweenOut = game:GetService("TweenService"):Create(frame, TweenInfo.new(1, "Circular", "In"), {Position = UDim2.new(1, 0, 0, 0)})

tweenOut:Play() -- You need to play it first so the Completed event works.
tweenOut.Completed:Wait() -- Now the event is available as it's made by the service itsself.

Thank you so much, I’ve been struggling with this for hours, it works so well now, thank you!

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