Tweening Issues

I’m trying to create a little announcement script, and I’m trying to Tween the announcement GUI when a button is clicked. I’ve looked through quite a few tutorials and attempted to modify my script to them, but am unable to find anything that contradicts my code.

local ann = game.StarterGui.StaffPanel.Announcement

script.Parent.MouseButton1Click:Connect(function()
	print("STARTED TWEEN")
	ann:TweenPosition(UDim2.new(0.301, 0,0.017, 0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.6, true)
	print("GOT TO SECOND TWEEN - WAITING")
	wait(10)
	
	ann:TweenPosition(
		ann:TweenPosition(UDim2.new(0.301, 0,-0.124, 0),Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.6, true)
	)
end)

As you can see, after the first Tween I set a message to be printed out. The second I hit the button that is meant to begin the tweeing process, booth the “STARTED TWEEN” and “GOT TO SECOND TWEEN - WAITING” are printed at the same time.

Anyone have any idea how this is to be fixed/achieved?

The reason both things are printed is because Tweens don’t yield. Consider using tween:Wait()

1 Like

I recommend you don’t use tweenPosition and instead use TweenService to have greater flexibility and be able to define the tween as a variable.
TweenService | Documentation - Roblox Creator Hub

Is TweenService for UI? I was only aware it was to be used on parts.

TweenService can be used for UI

If you don’t mind, how would that be done? I don’t really deal in Tweens and the devforum post only really focuses on how two conflicting parts would be tweened.

This is a basic example:

local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local object = ScreenGui:WaitForChild("ImageLabel")

object.AnchorPoint = Vector2.new(0.5, 0.5)

local targetPosition = UDim2.new(0.5, 0, 0.5, 0)

local tweenInfo = TweenInfo.new(2)
local tween = TweenService:Create(object, tweenInfo, {Position = targetPosition})

tween:Play()

There is another tutorial in roblox for tweening ui as well:
UI Animations | Documentation - Roblox Creator Hub
It shows how to tween position and everything that you need

1 Like

Worked, thanks so much. [yeehaw30chars]

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