[Edit 19/5/2018 V2]
This is my select the gamemode gui. I changed it into different bright colours to see the performance better.
It works perfectly. However, sometimes, it changes randomly and I do not know why. By watching the link below, you notice that the previous button does not transition efficiently. It does work but unexpectedly it glitches out. I cannot find anything wrong with it. Any ideas?
As you can see in the video, the runs perfectly on the first run but does random things after that. What is the problem here?
-- Declaration Section
-- / Player Precedence
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local Gui = PlayerGui:FindFirstChild("Gui")
-- / List of Actual Frames
local frameList = {
[1] = Gui.frame0,
[2] = Gui.frame1,
[3] = Gui.frame2,
[4] = Gui.frame3,
[5] = Gui.frame4,
[6] = Gui.frame5,
[7] = Gui.frame6
}
local CurrentFrame = 1
-- / Configuration for the movement of the frames
local AnimationLength = 0.5
local AnimationStyle = Enum.EasingStyle.Sine
local AnimationDirection = Enum.EasingDirection.Out
-- / Buttons
local previousButton = Gui.Previous
local nextButton = Gui.Next
-- Processing Section
local function ChangeFrames(MovingFramesArray)
for i, FrameData in pairs(MovingFramesArray) do
if FrameData == nil then return end
FrameData[1]:TweenSizeAndPosition(FrameData[2] or FrameData[1].Size, FrameData[3] or FrameData[1].Position, AnimationDirection, AnimationStyle, AnimationLength)
end
end
nextButton.MouseButton1Down:Connect(function(x, y)
if not frameList[CurrentFrame + 1] then return end
CurrentFrame = CurrentFrame + 1
-- The following data layout is: {Frame-Object, New-Size, New-Position}
local newFrameData = {frameList[CurrentFrame], UDim2.new(0, 405, 0, 370), UDim2.new(1, -650, 1, -500)} local oldFrameData
local newBackgroundFrameData
local oldBackgroundFrameData
if frameList[CurrentFrame - 1] then oldFrameData = {frameList[CurrentFrame - 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -950, 1, -450)} oldFrameData.ZIndex = 1 end
if frameList[CurrentFrame + 1] then newBackgroundFrameData = {frameList[CurrentFrame + 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -300, 1, -450)} newBackgroundFrameData.ZIndex = 1 end
if frameList[CurrentFrame - 2] then oldBackgroundFrameData = {frameList[CurrentFrame - 2], UDim2.new(0, 0, 0, 0), UDim2.new(1, -1250, 1, -450)} oldBackgroundFrameData.ZIndex = 1 end
ChangeFrames({newFrameData, oldFrameData, newBackgroundFrameData, oldBackgroundFrameData})
end)
previousButton.MouseButton1Down:Connect(function(x, y)
if not frameList[CurrentFrame - 1] then return end
CurrentFrame = CurrentFrame - 1
-- Same data layout: {Frame-Object, New-Size, New-Position}
local newFrameData = {frameList[CurrentFrame], UDim2.new(0, 405, 0, 370), UDim2.new(1, -650, 1, -500)}
local oldFrameData
local newBackgroundFrameData
local oldBackgroundFrameData
if frameList[CurrentFrame + 1] then oldFrameData = {frameList[CurrentFrame + 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -300, 1, -450)} oldFrameData.ZIndex = 1 end
if frameList[CurrentFrame - 1] then newBackgroundFrameData = {frameList[CurrentFrame - 1], UDim2.new(0, 320, 0, 292), UDim2.new(1, -950, 1, -450)} newBackgroundFrameData.ZIndex = 1 end
if frameList[CurrentFrame + 2] then oldBackgroundFrameData = {frameList[CurrentFrame + 2], UDim2.new(0, 0, 0, 0), UDim2.new(1, 0, 1, -450)} oldBackgroundFrameData.ZIndex = 1 end
ChangeFrames({newFrameData, oldFrameData, newBackgroundFrameData, oldBackgroundFrameData})
end)
Help?

4 comments
I'm not to sure, but by the looks of it it only bugs out when you're going to click the previous button
Yes. That is exactly the problem.
Are you checking the Output
^ No errors are seen.