How to make a Up and Down motion using TweenService

I have tried using many methods like while true loops and so on and noone seemed to be successful.

Current Code:

local gui = script.Parent
local PressStartText = gui.PressStartText
local tweenservice = game:GetService("TweenService")

local Tween_Info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

local function AnimateText(InstanceToAnimate, tweenInfo, PropertyToAnimate)
	while true do
		tweenservice:Create(InstanceToAnimate, tweenInfo, {Position = UDim2.new(0.5, 0, 0.6, 0)}):Play()
		wait(2)
		tweenservice:Create(InstanceToAnimate, tweenInfo, {Position = UDim2.new(0.5, 0, 0.8, 0)}):Play()
	end
end

AnimateText(PressStartText, Tween_Info)

I’m confused as to what you’re trying to do, you’ve posted a script with a looped tween but not actually given us a description of what you want other than an Up and Down motion, maybe it’s just me? Have you got an example?

Can’t you just make it tween the position of the thing you want to go up and down with the position of whatever it is?

1 Like

You didn’t put the PropertyToAnimate argument
I realised it was useless

I want an Infinite Up and Down motion of the TextLabel.

tween1 to go Up after completed it will go down and so on.

Is using TweenService necessary for you?

No, not really at all I just need the animation to work.

i don’t exactly know what you are trying to achieve, but as of my guess it is a tween that plays and reverts in a loop.
you can use this:

local tween_service = game:GetService("TweenService")
local ti =  Tweeninfo.new(time,easingstyle,easingdirection,math.huge --[[repeat count]],true --reverses the tween if true)
local goal = {}
ts:Create(instance,ti,goal)

TweenService has a repeat function and a reverse function why not use that?

You can use -1 on the repeat count for an infinite repeat

1 Like

I have tried but it doesn’t work, instead of animating itself down it just sets the position to X.Scale 0.8 and goes back to X.Scale 0.6.

You could use this article

https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenPosition

1 Like
local gui = script.Parent
local PressStartText = gui.PressStartText
local tweenservice = game:GetService("TweenService")

local Tween_Info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

local function AnimateText(InstanceToAnimate, tweenInfo, PropertyToAnimate)
	while true do
		local Tween1 = tweenservice:Create(InstanceToAnimate, tweenInfo, {Position = UDim2.new(0.5, 0, 0.6, 0)})
		Tween1:Play()
		Tween1.Completed:Wait()
		local Tween2 = tweenservice:Create(InstanceToAnimate, tweenInfo, {Position = UDim2.new(0.5, 0, 0.8, 0)})
		Tween2:Play()
		Tween2.Completed:Wait()
	end
end

AnimateText(PressStartText, Tween_Info)

Try this.

1 Like

If you are going to reuse the function you can wrap it in a task.spawn, though this is extremely inefficient especially when TweenService provides you with both a looping capability and an ability to reverse the tween.

local gui = script.Parent
local PressStartText = gui.PressStartText
local tweenservice = game:GetService("TweenService")

local Tween_Info = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.In)

local function AnimateText(InstanceToAnimate, tweenInfo, PropertyToAnimate)
	task.spawn(function()
		while true do
			local Tween1 = tweenservice:Create(InstanceToAnimate, tweenInfo, {Position = UDim2.new(0.5, 0, 0.6, 0)})
			Tween1:Play()
			Tween1.Completed:Wait()
			local Tween2 = tweenservice:Create(InstanceToAnimate, tweenInfo, {Position = UDim2.new(0.5, 0, 0.8, 0)})
			Tween2:Play()
			Tween2.Completed:Wait()
		end
	end)
end

AnimateText(PressStartText, Tween_Info)

Should work

local gui = script.Parent
local PressStartText = gui.PressStartText

local function AnimateText(InstanceToAnimate, tweenInfo, PropertyToAnimate)
    InstanceToAnimate:TweenPosition(
        UDim2.new(0.5, 0, 0.6, 0),
        Enum.EasingDirection.Out,
        "Quad",
        2,
        true,
        function(state)
            InstanceToAnimate:TweenPosition(
                UDim2.new(0.5, 0, 0.6, 0),
                Enum.EasingDirection.Out,
                "Quad",
                2,
               true,
            )
        end
    )
end

while true do
   AnimateText(PressStartText, Tween_Info)
end
1 Like