Tween acting weird, how can I fix?

Hello! I hope you are having a great day so far! I am certainly having a good one also.


The Problem:

I have a little problem. I am trying to re-create this for one of my games:


Here is my concept so far:

The tween starts to act a little funny. First of all, it sometimes stops. Second, the tween will set the position of the current slide without it being done.

The Code:

Anything before this code are the images in the table, and all of the TweenInfo.

while true do
	script.Parent.ImageLabel2.Position = UDim2.new(-0.5, 0, 0, 0)
	script.Parent.ImageLabel1:TweenPosition(UDim2.new(-0.5, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3)
	wait(3)
	script.Parent.ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
	fadeF1:Play()
	fadeF2in:Play()
	script.Parent.ImageLabel1.Position = UDim2.new(0, 0, 0, 0)
	script.Parent.ImageLabel2:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3)
	wait(3)
	script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
	fadeF2:Play()
	fadeF1in:Play()
end
The before code
local ts = game:GetService("TweenService")


local f1 = script.Parent.ImageLabel1

local goal1 = {}
goal1.ImageTransparency = 1
local tweenInfoForF1 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local fadeF1 = ts:Create(f1, tweenInfoForF1, goal1)

local goal1in = {}
goal1in.ImageTransparency = 0
local tweenInfoForin1in = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local fadeF1in = ts:Create(f1, tweenInfoForin1in, goal1in)

local f2 = script.Parent.ImageLabel2
local goal2 = {}
goal2.ImageTransparency = 1
local tweenInfoForF2 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local fadeF2 = ts:Create(f2, tweenInfoForF2, goal2)

local goal2in = {}
goal2in.ImageTransparency = 0
local tweenInfoForin2in = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local fadeF2in = ts:Create(f2, tweenInfoForin2in, goal2in)

local imageTable = {
	"rbxassetid://6159040162",
	"rbxassetid://6192412177",
	"rbxassetid://6192412308",
}

script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]

If you can help, please let me know. Thanks! WE

1 Like

I believe why this is happening, is cause you haven’t set the fifth parameter when using TweenPosition

The fifth parameter is supposed to override any other tweens when calling it, try this:

while true do
	script.Parent.ImageLabel2.Position = UDim2.new(-0.5, 0, 0, 0)
	script.Parent.ImageLabel1:TweenPosition(UDim2.new(-0.5, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3, true)
	wait(3)
	script.Parent.ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
	fadeF1:Play()
	fadeF2in:Play()
	script.Parent.ImageLabel1.Position = UDim2.new(0, 0, 0, 0)
	script.Parent.ImageLabel2:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3, true)
	wait(3)
	script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
	fadeF2:Play()
	fadeF1in:Play()
end
2 Likes

That fixes that problem, but now, there is a new problem:

The Code:

local ts = game:GetService("TweenService")


local f1 = script.Parent.ImageLabel1

local goal1 = {}
goal1.ImageTransparency = 1
local tweenInfoForF1 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF1 = ts:Create(f1, tweenInfoForF1, goal1)

local goal1in = {}
goal1in.ImageTransparency = 0
local tweenInfoForin1in = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF1in = ts:Create(f1, tweenInfoForin1in, goal1in)

local f2 = script.Parent.ImageLabel2
local goal2 = {}
goal2.ImageTransparency = 1
local tweenInfoForF2 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF2 = ts:Create(f2, tweenInfoForF2, goal2)

local goal2in = {}
goal2in.ImageTransparency = 0
local tweenInfoForin2in = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF2in = ts:Create(f2, tweenInfoForin2in, goal2in)

local imageTable = {
	"rbxassetid://6159040162",
	"rbxassetid://6192412177",
	"rbxassetid://6192412308",
}

script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]

while wait() do
	script.Parent.ImageLabel1:TweenPosition(UDim2.new(-0.5, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3, true)
	wait(3)
	script.Parent.ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
	fadeF1:Play()
	wait(1)
	fadeF2in:Play()
	script.Parent.ImageLabel2.Position = UDim2.new(-0.5, 0, 0, 0)
	script.Parent.ImageLabel2:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3, true)
	wait(3)
	script.Parent.ImageLabel1.Position = UDim2.new(0, 0, 0, 0)
	script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
	fadeF2:Play()
	wait(1)
	fadeF1in:Play()
end
1 Like

It looks like the second tween isn’t disappearing & the first tween is re-appearing hm, so it’s somewhere along these lines:

Could you try setting the ImageLabel’s transparency to 1 when it finishes the Tween?

1 Like

That is what the Tweens fadeF2 and fadeF1 do.

1 Like

Yeah but that doesn’t seem to be the case, as it keeps resetting
Just for experimental purposes, could you try this loop and see what happens?

while wait() do
    print("Tween playing")
	script.Parent.ImageLabel1:TweenPosition(UDim2.new(-0.5, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3, true)
	wait(3)
    print("Playing fade tween")
	script.Parent.ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
	fadeF1:Play()
	wait(1)
    print("Tween playing/Making previous image invisible")
    script.Parent.ImageLabel1.ImageTransparency = 1
	fadeF2in:Play()
	script.Parent.ImageLabel2.Position = UDim2.new(-0.5, 0, 0, 0)
	script.Parent.ImageLabel2:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 3, true)
	wait(3)
    print("Playing fade tween")
	script.Parent.ImageLabel1.Position = UDim2.new(0, 0, 0, 0)
	script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
	fadeF2:Play()
	wait(1)
    print("Tween playing/Making previous image invisible")
    script.Parent.ImageLabel2.ImageTransparency = 1
	fadeF1in:Play()
end

Maybe this works for you:

local TweenService = game:GetService("TweenService")
function Tweens(Obj,Time,Props)
    local T = TweenService:Create(Obj,TweenInfo.new(Time),Props)
    T:Play()
    return T
end

local ImageLabel1 = script.Parent.ImageLabel1

while true do
    script.Parent.ImageLabel2.Position = UDim2.new(-0.5, 0, 0, 0)
    Tweens(ImageLabel1,3,{["Position"] = UDim2.fromScale(-0.5, 0)}).Completed:Wait()
    script.Parent.ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
    fadeF1:Play()
    fadeF2in:Play()
    script.Parent.ImageLabel1.Position = UDim2.new(0, 0, 0, 0)
    Tweens(ImageLabel1,3,{["Position"] = UDim2.fromScale(0, 0)}).Completed:Wait()
    script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
    fadeF2:Play()
    fadeF1in:Play()
end

local ts = game:GetService("TweenService")


local f1 = script.Parent.ImageLabel1

local goal1 = {}
goal1.ImageTransparency = 1
local tweenInfoForF1 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF1 = ts:Create(f1, tweenInfoForF1, goal1)

local goal1in = {}
goal1in.ImageTransparency = 0
local tweenInfoForin1in = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF1in = ts:Create(f1, tweenInfoForin1in, goal1in)

local f2 = script.Parent.ImageLabel2
local goal2 = {}
goal2.ImageTransparency = 1
local tweenInfoForF2 = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF2 = ts:Create(f2, tweenInfoForF2, goal2)

local goal2in = {}
goal2in.ImageTransparency = 0
local tweenInfoForin2in = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true, 0)
local fadeF2in = ts:Create(f2, tweenInfoForin2in, goal2in)

local imageTable = {
	"rbxassetid://6159040162",
	"rbxassetid://6192412177",
	"rbxassetid://6192412308",
}

function Tweens(Obj,Time,Props)
	local T = ts:Create(Obj,TweenInfo.new(Time),Props)
	T:Play()
	return T
end

local ImageLabel1 = script.Parent.ImageLabel1

while true do
	script.Parent.ImageLabel2.Position = UDim2.new(-0.5, 0, 0, 0)
	Tweens(ImageLabel1,3,{["Position"] = UDim2.fromScale(-0.5, 0)}).Completed:Wait()
	script.Parent.ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
	fadeF1:Play()
	fadeF2in:Play()
	script.Parent.ImageLabel1.Position = UDim2.new(0, 0, 0, 0)
	Tweens(ImageLabel1,3,{["Position"] = UDim2.fromScale(0, 0)}).Completed:Wait()
	script.Parent.ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
	fadeF2:Play()
	fadeF1in:Play()
end

I don’t know if I’m correct, but I think EasingStyle should be before EasingDirection.

I never use EasingDirection, so I don’t exactly know, but this is the only thing I find weird.

If I’m wrong, you can correct me, and I can use this knowledge for the future.

I don’t know what fadeF2 and fadeF1in are, since you didn’t show those parts.

Okay, I now know that.

Reference for TweenPosition's parameters:


Referring back, I think I may know how to fix it but it’ll take some time

1 Like

How does it look? Does it look the same as what you want?

https://gyazo.com/4f2bd1a3d49e89963135b0ae3819c4c1

Sort of, but constantly moving and full screen.

The image was only for testing, here the code I use:

local TweenService = game:GetService("TweenService")

function Tweens(Obj,Time,Props)
    local T = TweenService:Create(Obj,TweenInfo.new(Time),Props)
    T:Play()
    return T
end

local ImageLabel1 = script.Parent.ImageLabel1
local ImageLabel2 = script.Parent.ImageLabel2

while true do
    ImageLabel1.ImageTransparency = 0
    ImageLabel2.ImageTransparency = 1
    ImageLabel2.Position = UDim2.fromScale(-0.5, 0)
    Tweens(ImageLabel1,2,{["Position"] = UDim2.fromScale(-0.5, 0)}).Completed:Wait()
    Tweens(ImageLabel1,2,{["ImageTransparency"] = 1})
    Tweens(ImageLabel2,2,{["ImageTransparency"] = 0}).Completed:Wait()
    -- ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
    -- fadeF1:Play()
    -- fadeF2in:Play()
    ImageLabel1.Position = UDim2.fromScale(0, 0)
    Tweens(ImageLabel2,2,{["Position"] = UDim2.fromScale(0, 0)}).Completed:Wait()
    Tweens(ImageLabel1,2,{["ImageTransparency"] = 0})
    Tweens(ImageLabel2,2,{["ImageTransparency"] = 1}).Completed:Wait()
    -- ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
    -- fadeF2:Play()
    -- fadeF1in:Play()
end

I hope I have been able to help you.

local TweenService = game:GetService("TweenService")

local imageTable = {
	"rbxassetid://6159040162",
	"rbxassetid://6192412177",
	"rbxassetid://6192412308",
}

function Tweens(Obj,Time,Props)
	local T = TweenService:Create(Obj,TweenInfo.new(Time),Props)
	T:Play()
	return T
end

local ImageLabel1 = script.Parent.ImageLabel1
local ImageLabel2 = script.Parent.ImageLabel2

while true do
	Tweens(ImageLabel1,2,{["Position"] = UDim2.fromScale(-0.5, 0)}).Completed:Wait()
	Tweens(ImageLabel1,2,{["ImageTransparency"] = 0})
	ImageLabel1.Position = UDim2.fromScale(0, 0)
	Tweens(ImageLabel2,2,{["ImageTransparency"] = 1})
	ImageLabel1.Image = imageTable[math.random(1, #imageTable)]
	Tweens(ImageLabel2,2,{["Position"] = UDim2.fromScale(0, 0)}).Completed:Wait()
	Tweens(ImageLabel1,2,{["ImageTransparency"] = 1})
	ImageLabel2.Position = UDim2.fromScale(-0.5, 0)
	Tweens(ImageLabel2,2,{["ImageTransparency"] = 0})
	ImageLabel2.Image = imageTable[math.random(1, #imageTable)]
end

Super Close!

Do you have any suggestions?

1 Like