Help with TweenService

So I am wanting to make an arrow which opens and closes GUI’s with a tween, but I ran into an issue. Please watch the video, and look at the code, so you understand the issue.

Here is the code in the video:

local TwitterButton = script.Parent.Parent.Twitter
local InventoryButton = script.Parent.Parent.Inventory
local Shop = script.Parent.Parent.Shop
local Back = script.Parent.Parent.Back
local Forward = script.Parent.Parent.Forward

local function Tween()

    TwitterButton:TweenPosition(UDim2.new(-1, 0,0.026, 219),"InOut","Sine",1)
    wait(.0001)
    InventoryButton:TweenPosition(UDim2.new(-1, 0,0.422, 0),"InOut","Sine",1)
    wait(.0001)
    Shop:TweenPosition(UDim2.new(-1, 0,0.544, 0),"InOut","Sine",1)
    wait(.0001)

    script.Parent:TweenPosition(UDim2.new(0.01, 0,0.436, 0),"InOut","Sine",1)
    wait(.0001)
    
    
end

local function TweenForward()
    TwitterButton:TweenPosition(UDim2.new(0.23, 0,0.026, 219),"InOut","Sine",1)
    wait(.0001)
    InventoryButton:TweenPosition(UDim2.new(0.23, 0,0.422, 0),"InOut","Sine",1)
    wait(.0001)
    Shop:TweenPosition(UDim2.new(0.23, 0,0.544, 0),"InOut","Sine",1)
    wait(.0001)
    script.Parent:TweenPosition(UDim2.new(0.1, 0,0.436, 0),"InOut","Sine",1)
    wait(.0001)
end

Back.MouseButton1Click:Connect(function()


    Tween()


end)


Forward.MouseButton1Click:Connect(function()


    TweenForward()


end)



I’m not to sure, but in tweening with ui’s dont you add a true or false?

I am very confused with your statement.

I might be wrong but I mean like this:

    script.Parent:TweenPosition(UDim2.new(0.1, 0,0.436, 0),"InOut","Sine",1, false)

Or is that with parts, I don’t really use tweening so yeah.

I don’t know if this is your problem but when tweening with different styles you have to do

Enum.EasingStyle.Linear

or something like that Im on mobile so I can’t check.

Your correct you do need styles:

script.Parent:TweenPosition(UDim2.new(0.1, 0,0.436, 0),Enum.(What You Need).InOut,Enum.EasingStyle.Sine,1, false or true)

Again i might be wrong

TwitterButton:TweenPosition(UDim2.new(0.23, 0,0.026, 219), Enum.EasingDirection.InOut,Enum.EasingStyle.Sine, 1, false)

Doesn’t work at all, and nothing is in the output.

    script.Parent:TweenPosition(UDim2.new(0.1, 0,0.436, 0),"InOut","Sine",1, false)

Try what i did before, I think you supposed to do the boolean

Again, it doesn’t work. I just tried and the same thing happened.

1 Like

Did you do it for all of them? What was the specific error?

There isn’t an error in the output, your code doesn’t work, but I appreciate the help.

Maybe try saying play:(Your Tween)

See if it works

Before I get into answering your question, there are multiple things that aren’t necessarily bad, but can improve your code in the long run that you should probably consider.

Sometimes scripts will load before the instances, meaning that if your script runs before a UI is added, the entire script will fail. For scripts that run immediately as the game starts or when the player joins the game, you should use :WaitForChild("") (or for example in your code local TwitterButton = script.Parent.Parent:WaitForChild("Twitter"))

Secondly, wait() is deprecated and its successor is task.wait(). Also wait() can only go down to 0.03 Seconds, while task.wait() by itself will run every Heartbeat.

Finally Tween Position requires Enums for Easing Direction and Style. These can be found on their dedicated DevHub documentation.

Also you can connect functions with events ie. Forward.MouseButton1Click:Connect(Tween)

Hope this helps!

I dont believe this is the problem. It would work fine if you just quote the name of the animation style, rather mentioning Enum.EasingStyle or Enum.EasingDirection. But if you were to use TweenService, you do need to mention Enum.EasingStyle

Sorry to suggest something that you’ve probably already done, but check out TweenService on the developer wiki here: TweenService | Roblox Creator Documentation

local TweenService = game:GetService("TweenService")
 
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = game.Workspace
 
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
)
 
local tween = TweenService:Create(part, tweenInfo, {Position = Vector3.new(0, 30, 0)})
 
tween:Play()
wait(10)
tween:Cancel() -- cancel the animation after 10 seconds

I’d recommend using this as a reference to make sure that you’ve scripted your Tween properly.