How would I make the Shop to bounce back to the start position?

  1. What do you want to achieve? Keep it simple and clear!

Alright, so there are one textbutton responsible for open/close the Shop. When you click on “Open Shop” the shop will bounce to the end position. Then the shop will change the text to “Close” and the color to red. When you click on “Close” it should bounce back to the start position.

I am sorry for not being as specific as the things I want to achieve.

  1. What is the issue? Include screenshots / videos if possible!

There is no error in the output and when I click on the button (Open Shop) it bounce to the end position. The thing is that it doesn’t bounce back to the start position after clicking on the same button.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried doing sum research on google and developer forum but I could not find a way to fix this.

local OpennCloseUI = script.Parent.OpenNCloseUI
local Shop = script.Parent.Shop
local player = game.Players.LocalPlayer
	
OpennCloseUI.MouseButton1Click:Connect(function(player)
	if Shop.Visible == false  then
		Shop.Visible = true
		Shop:TweenPosition(
			UDim2.new(0.385, 0,0.181, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
		OpennCloseUI.Text = "Close"
	else
		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
		Shop:TweenPosition(
			UDim2.new(0.403, 0,-0.608, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		OpennCloseUI.Text = "Open Shop"
		Shop.Visible = false
	end
end)

The issue with your script is the fact that you hide the shop as soon as you start the tween:

local OpennCloseUI = script.Parent.OpenNCloseUI
local Shop = script.Parent.Shop
local player = game.Players.LocalPlayer

OpennCloseUI.MouseButton1Click:Connect(function(player)
	if Shop.Visible == false  then
		Shop.Visible = true
		Shop:TweenPosition(
			UDim2.new(0.385, 0,0.181, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
		OpennCloseUI.Text = "Close"
	else
		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
		Shop:TweenPosition(
			UDim2.new(0.403, 0,-0.608, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		
		wait(1) -- Wait for the tween to finish before hiding the shop
		
		OpennCloseUI.Text = "Open Shop"
		Shop.Visible = false
	end
end)

ths is what happen when I put the wait() the Shop and the text of the button delay when changing the text back to |Open Shop| and making the Shop visible.

change the

UDim2.new(0.403, 0,-0.608, 0)

to

UDim2.new(0.385, 0,-0.6, 0)

so I changed it but the text seems to be behind the line like it delays before changing it.

Updated Code:

local OpennCloseUI = script.Parent.OpenNCloseUI
local Shop = script.Parent.Shop
local player = game.Players.LocalPlayer
	
OpennCloseUI.MouseButton1Click:Connect(function(player)
	if Shop.Visible == false then
		Shop.Visible = true
		Shop:TweenPosition(
			UDim2.new(0.385, 0,0.181, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
		OpennCloseUI.Text = "Close"
	else
		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
		Shop:TweenPosition(
			UDim2.new(0.385, 0,-0.6, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		
		wait(1)
		
		OpennCloseUI.Text = "Open Shop"
		Shop.Visible = false
	end
end)

ok, use this:

local OpennCloseUI = script.Parent.OpenNCloseUI
local Shop = script.Parent.Shop
local player = game.Players.LocalPlayer
	
OpennCloseUI.MouseButton1Click:Connect(function(player)
	if Shop.Visible == false then
		Shop.Visible = true
		Shop:TweenPosition(
			UDim2.new(0.385, 0,0.181, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
		OpennCloseUI.Text = "Close"
	else
		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
		Shop:TweenPosition(
			UDim2.new(0.385, 0,-0.6, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		
		delay(1, function()
Shop.Visible = false
		end)

		OpennCloseUI.Text = "Open Shop"
	end
end)

it changes the text after u click on close button but the tweening part of the Shop delay like 1 second before bouncing back to the start position.

Try making wait time shorter, for example try changing it from 1 to 0.75.

I tried that but I’m still having the same problem.

Use @SingaporeSteadyLah’s code, but put the

delay(1, function()
    Shop.Visible = false
end)

before you call the TweenPosition function

I updated the code it still seems to be having the same problem.

Also this happens when I click it too fast

You can fix that by adding debounce system:

local OpennCloseUI = script.Parent.OpenNCloseUI
local Shop = script.Parent.Shop
local player = game.Players.LocalPlayer
local canToggle = true

OpennCloseUI.MouseButton1Click:Connect(function(player)
	if Shop.Visible == false and canToggle then
		canToggle = false

		Shop.Visible = true
		Shop:TweenPosition(
			UDim2.new(0.385, 0,0.181, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		
		delay(1, function() -- I also forgot about that
			canToggle = true
		end)
		
		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
		OpennCloseUI.Text = "Close"
	elseif canToggle then
		canToggle = false

		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
		Shop:TweenPosition(
			UDim2.new(0.385, 0,-0.6, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Elastic,
			1,
			false
		)

		delay(1, function()
			Shop.Visible = false
			canToggle = true -- Actually it should be here
		end)

		OpennCloseUI.Text = "Open Shop"

		-- canToggle = true - not here
	end
end)

Edit: I realized that It can’t work. Setting canToggle back to true should happen in the spawned function.

1 Like

Hi, the issue you have (may have been solved already), is that you are disabling the visibility of the frame as soon as the tween runs, so the tween is running but the frame is just not visible for you to see. Very simple fix is that you could add a :wait() then in the brackets just put the length of the tween, so it knows how long to wait. But you will need to set a time value into the tween as you haven’t done so.

Example Script

    OpennCloseUI.MouseButton1Click:Connect(function(player)
    	if Shop.Visible == false  then
    		Shop.Visible = true
    		Shop:TweenPosition(
                1, -- Length(at the moment it is set to 1)
    			UDim2.new(0.385, 0,0.181, 0),
    			Enum.EasingDirection.Out,
    			Enum.EasingStyle.Elastic,
    			1,
    			false
    		)
    		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
    		OpennCloseUI.Text = "Close"
    	else
    		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
    		Shop:TweenPosition(

                1, -- Length(at the moment it is set to 1)
    			UDim2.new(0.403, 0,-0.608, 0),
    			Enum.EasingDirection.InOut,
    			Enum.EasingStyle.Elastic,
    			1,
    			false
    		)
    		OpennCloseUI.Text = "Open Shop"
            wait(1)
    		Shop.Visible = false
    	end
    end)

what do you mean time value? Are you talking about NumberValue?

before & after clicking the Open Shop button the shop doesn’t bounce back to the start position instead it just make the Shop visible

Show the current script’s code.

local OpennCloseUI = script.Parent.OpenNCloseUI
local Shop = script.Parent.Shop
local player = game.Players.LocalPlayer
local canToggle = true

OpennCloseUI.MouseButton1Click:Connect(function(player)
	if Shop.Visible == false and canToggle then
		canToggle = false

		Shop.Visible = true
		Shop:TweenPosition(
			UDim2.new(0.385, 0,0.181, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Elastic,
			1,
			false
		)
		OpennCloseUI.BackgroundColor3 = Color3.new(1, 0, 0)
		OpennCloseUI.Text = "Close"

		canToggle = true
	elseif canToggle then
		canToggle = false

		OpennCloseUI.BackgroundColor3 = Color3.new(0, 255, 0)
		Shop:TweenPosition(
			UDim2.new(0.385, 0,-0.6, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Elastic,
			1,
			false
		)

		delay(1, function()
			Shop.Visible = false
			canToggle = true -- Actually it should be here
		end)

		OpennCloseUI.Text = "Open Shop"

		-- canToggle = true - not here
	end
end)

I edited the script here few times and that’s how you didn’t copy something important in my version of the script (basically my bad).