Frame are overlapping to each other

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

Current Behavior
Video:

Get all the frames that pop up when you press the buttons, and set all of them to Visible = false except the one you want to be on the screen.

1 Like

Yeah and just tween them back if they’re visible

Can you give me an example on how to do it?

for i, v in pairs(allTheFrames) do
      v.Visible = false
end

theFrameYouWant.Visible = true

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

you are supposed to set currentframe before you tween

It doesn’t fix the issue and it still doesn’t work

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

what is the parent of the frames on the center of the screen that pop up?

Which line you got error sorry i am mobile lol

there is no error now it still doesn’t get rid the frame 1 if I open frame 2.

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

1 Like

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.

local Tween = TweenService:Create(ButtonFrames[currentframe], FrameTweenInfo, {Position = UDim2.new(0.5, 0, -0.7, 0)})
Tween:Play()
Tween.Completed:Wait()
ButtonDebounce = false

https://developer.roblox.com/en-us/api-reference/event/TweenBase/Completed