When a player presses button 1, it opens frame 1. Then if a player presses button 2, it gets rid of frame 1 and opens frame 2.
Local Script
local function TweenFrame()
local FrameTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut)
for _,v in pairs(TopButtonsFrame:GetChildren()) do
if v:IsA("Frame") then
v.TextButton.MouseButton1Click:Connect(function()
if not ButtonDebounce then
ButtonDebounce = true
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
else
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
task.wait(0.25)
ButtonDebounce = false
end
end)
end
end
end
You can add variable name it currentframe like that
local function TweenFrame()
local currentframe
local FrameTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut)
for _,v in pairs(TopButtonsFrame:GetChildren()) do
if v:IsA("Frame") then
v.TextButton.MouseButton1Click:Connect(function()
if not ButtonDebounce then
ButtonDebounce = true
TweenService:Create(ButtonFrames[currentframe],FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
currentframe = v.Name
else
currentframe = v.Name
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
task.wait(0.25)
ButtonDebounce = false
end
end)
end
end
end
If you open frame now thats mean variable currentframe will equal frame name you opened and if you preseed any button will get curent frame back
I got an error “invalid argument #2 (string expected, got nil)”
local function TweenFrame()
local currentframe
local FrameTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut)
for _,v in pairs(TopButtonsFrame:GetChildren()) do
if v:IsA("Frame") then
v.TextButton.MouseButton1Click:Connect(function()
if not ButtonDebounce then
ButtonDebounce = true
TweenService:Create(ButtonFrames[currentframe],FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
currentframe = v.Name
else
currentframe = v.Name
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
task.wait(0.25)
ButtonDebounce = false
end
end)
end
end
end
local function TweenFrame()
local currentframe
local FrameTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut)
for _,v in pairs(TopButtonsFrame:GetChildren()) do
if v:IsA("Frame") then
v.TextButton.MouseButton1Click:Connect(function()
if not ButtonDebounce then
ButtonDebounce = true
currentframe = v.Name
TweenService:Create(ButtonFrames[currentframe],FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
else
currentframe = v.Name
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
task.wait(0.25)
ButtonDebounce = false
end
end)
end
end
end
You have to loop through all the frames that could be on the centre of the screen and disable visibility on the ones you dont want to be seen at that moment
local function TweenFrame()
local currentframe
local FrameTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Elastic, Enum.EasingDirection.InOut)
for _,v in pairs(TopButtonsFrame:GetChildren()) do
if v:IsA("Frame") then
v.TextButton.MouseButton1Click:Connect(function()
if not ButtonDebounce then
ButtonDebounce = true
currentframe = v.Name
TweenService:Create(ButtonFrames[v.Name], FrameTweenInfo, {Position = UDim2.new(0.5, 0, 0.5, 0)}):Play()
else
TweenService:Create(ButtonFrames[currentframe], FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)}):Play()
task.wait(0.6)
ButtonDebounce = false
end
end)
end
end
end
I hope this worked
And i think too task.wait should equal or greater than tween time to not be glitched
Instead of arbitrarily yielding the thread until the tween’s completion you should assign the tween to a variable and listen for its ‘Completed’ event/signal to fire.