Gui moving to {0,0} position after tweening

Hello. I have this issue for 2 days, I contacted so many people but none of them could solve this problem.
Problem is, selected Gui’s position becomes {0,0},{0,0} after the tween but it’s not even an option.
This is what happens:

And this is the explorer:
image
(it is fine with other Gui that isn’t selected)

This was for the left button. On the right button, both of the Gui’s are being moved to {0,0},{0,0} position.

Script:

--Definitions
local OutFrame = script.Parent
local SelectedSword = game.ReplicatedStorage.Values.SelectedSwordName.SelectedSwordName0
local remote = game.ReplicatedStorage.RemoteEvents.ValueChanger
local LeftArrow = OutFrame:WaitForChild("LeftArrow")
local RightArrow = OutFrame:WaitForChild("RightArrow")
local VPFrameFolder = OutFrame:WaitForChild("ViewportFrames")
local allVPs = VPFrameFolder:GetChildren()
local tweenService = game:GetService("TweenService")
local outFramePosLeft = UDim2.new(0.01,0,0.35,0)
local outFramePosRight = UDim2.new{0.7,0,0.35,0}
local Center = UDim2.new{0.35,0,0.35,0}
--Indexes
local index = 1
local indexMin = 1
local indexMax = 2
--Tweens
local function leftSwipe(frame)
	print("LeftSwipe")
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
	local tween = tweenService:Create(frame, tweenInfo, {Position = outFramePosLeft})
	tween:Play()
	wait(0.6)
	frame.Visible = false
end

local function rightSwipe(frame)
	print("RightSwipe")
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
	local tween = tweenService:Create(frame, tweenInfo, {Position = outFramePosRight})
	tween:Play()
	wait(0.6)
	frame.Visible = false
end

local function toCenterSwipe(frame)
	print("ToCenterSwipe")
	if frame.Visible == false then frame.Visible = true end
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
	local tween = tweenService:Create(frame, tweenInfo, {Position = Center})
	tween:Play()
end
--Functions
local function indexCal(buttonname)
	if type(buttonname) ~= 'string' then
		assert(false, "Put a string here.")
	elseif buttonname == "Right" then
		index = index + 1
		if index > indexMax then
			index = indexMin
		end
	elseif buttonname == "Left" then
		index = index - 1
		if index < indexMin then
			index = indexMax
		end
	end
end

local function lookForGui(index)
	index = tostring(index)
    for _, v in pairs(allVPs)do
        local stringName = v.Name
        local stringNameAll = string.split(stringName, " ")
        for i, v1 in pairs (stringNameAll) do
            if v1 == index then
                print(v1)
				remote:FireServer("SelectedSwordName0", v.Name)
                return v
			else
				stringName = nil
				stringNameAll = nil
            end
        end
    end
    print(nil)
    return nil
end

local function calculatePreviousLeft(index)
	if index-1 >= indexMin then return index-1 else return indexMax end
end

local function calculatePreviousRight(index)
	if index+1 <= indexMax then return index+1 else return indexMin end
end

local function onRightButtonClick()
	indexCal("Right")
	local NextGui = lookForGui(index)
	local previousGui = lookForGui(calculatePreviousLeft(index))
	if previousGui then
		rightSwipe(previousGui)
	else
		warn("Something is wrong with Gui index.")
	end
	if NextGui then
		toCenterSwipe(NextGui)
	else
		warn("Something is wrong with Gui index.")
	end
end

local function onLeftButtonClick()
	indexCal("Left")
	local NextGui = lookForGui(index)
	local previousGui = lookForGui(calculatePreviousLeft(index))
	if previousGui then
		leftSwipe(previousGui)
	else
		warn("Something is wrong with Gui index.")
	end
	if NextGui then
		toCenterSwipe(NextGui)
	else
		warn("Something is wrong with Gui index.")
	end
end
--Events
RightArrow.MouseButton1Click:Connect(onRightButtonClick)
LeftArrow.MouseButton1Click:Connect(onLeftButtonClick)

Note:

  • Indexes are correct.
  • This started when I changed Gui anchor point to 0. It was 0.5 before. I replaced all values with new ones when I changed the anchor point.
5 Likes

Just a side note, but there’s actually a specific method for tweening UI objects, it’s called :TweenPosition

frame:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingStyle.Linear, Enum.EasingDirection.Out, duration, can_be_overriden)

As C_Sharper said, you should look into UI:TweenPosition

local outFramePosRight = UDim2.new{0.7,0,0.35,0}
local Center = UDim2.new{0.35,0,0.35,0}

You need to use regular parentheses on these lines. Calling UDim2.new with a table will return a default UDim2 (0, 0, 0, 0).


Not relevant - this is not OP’s issue. Either way, TweenService is recommended because it is more flexible.

6 Likes

Oh didn’t see that at all. But yes, use TweenService and make sure to use parentheses.

Why is it more recommended for tweening UI? If anything I’d figure it’d be more convenient as you don’t need to create a new TweenInfo instance each time you tween a frame

It also never mentions :TweenPosition being deprecated on the wiki page

Works perfectly. And really, I’m tired of my basic mistakes… I couldn’t see these aren’t regular parentheses. I knew that’d happen one day if I continue copying from positions. Thank you by the way.

1 Like

Does it have any performance difference compared to regular tweening?

Probably not. I just figured it’d be more ideal to use in your case as that method is specifically built for tweening UI elements, and from my perspective it seemed like extra work using TweenService instead.

But either way, it’s your call. Was just a side-note not really meant to be off-topic by any means :confused:

1 Like

Here is a helpful explanation (you can search the forum for this yourself too)

1 Like

thanks, mate helped me a lot I ran into a similar issue and it kept bugging me