I need help with my tweening guis

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

Hello, so basically I’m making a script that tweens the size and position of a Crafting UI when you click on a button.

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

the Crafting UI tweens to its UDim that I wanted. But the problem is that when I kept clicking onto the button the v2 also know as bool/debounce couldn’t stop players from clicking it before tweening back. Resulting it to overrun the tween (Haven’t finish playing the tween) and making the Crafting UI not visible.

local storebutton = script.Parent.storeframe:WaitForChild("storebutton")
local v2 = true

local function storebuttononclick()
    storebutton:TweenPosition(UDim2.new(-0.014, 0,0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false)
    if script.Parent.ImageLabel.Visible == false and v2 then
    v2 = false;
    script.Parent.ImageLabel.Visible = true
    OpenCraftingUI()
    Click()
    storebutton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
        
    v2 = true
elseif v2 then
    v2 = false
        
    storebutton.BackgroundColor3 = Color3.fromRGB(0, 166, 249)
    Error()
    CloseCraftingUI()
        
    delay(1, function()
    storebutton:TweenPosition(UDim2.new(-0.014, 0,-0.134, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false)
    script.Parent.ImageLabel.Visible = false
        v2 = true
        end)
    end
end

Since you’re wanting to detect when the Tween gets finished when a Player clicks, use a callback function to check when the UIObject is done tweening

local storebutton = script.Parent.storeframe:WaitForChild("storebutton")
local Tweening = false
local v2 = true

local function Callback(State)
    if State == Enum.TweenState.Completed then
        Tweening = false

        if not v2 then
            v2 = true
        else
            v2 = false
        end
    end
end

local function storebuttononclick()

    if not Tweening then
        Tweening = true

        if not v2 then
            storebutton:TweenPosition(UDim2.new(-0.014, 0,0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false, Callback)
            script.Parent.ImageLabel.Visible = true
            storebutton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
            OpenCraftingUI()
            Click()

        elseif v2 then
            storebutton:TweenPosition(UDim2.new(-0.014, 0,-0.134, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false, Callback)
            script.Parent.ImageLabel.Visible = false
            storebutton.BackgroundColor3 = Color3.fromRGB(0, 166, 249)
            Error()
            CloseCraftingUI()
        end
    end

end
local guiObject = script.Parent
local imageLabel = guiObject:WaitForChild("ImageLabel")
local storebutton = guiObject:WaitForChild("storeframe"):WaitForChild("storebutton")
local open = false
local tweening = false

local function callback(state)
	if state == Enum.TweenStatus.Completed then
		tweening = false
	end
end

local function storebuttononclick()
	if tweening then return end
	tweening = true
	open = not open
	
	if not open then
		imageLabel.Visible = true
		storebutton:TweenPosition(UDim2.fromScale(-0.014, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false, callback)
		OpenCraftingUI()
		Click()
		storebutton.BackgroundColor3 = Color3.new(1, 0, 0)
		
	elseif open then
		storebutton.BackgroundColor3 = Color3.new(0, 0.75, 1)
		Error()
		CloseCraftingUI()
		storebutton:TweenPosition(UDim2.fromScale(-0.014, -0.134), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false, callback)
		imageLabel.Visible = false
	end
end

storebutton.MouseButton1Click:Connect(function(storebuttononclick)

Don’t forget to connect the function at the end to the MouseButton1Click event of the GuiObject instance. I’ve made various improvements/minor changes to the original code, if you need any explained don’t hesitate to ask.

that didn’t work I tried connecting the function at the end but my button just stopped working.

local storebutton = script.Parent.storeframe:WaitForChild("storebutton")
local settingsbutton = script.Parent.settingsframe:WaitForChild("settingbutton")
local tweening = false
local v2 = false 

local function Callback(State)
	if State == Enum.TweenStatus.Completed then
		tweening = false
	end
end

local function OpenCraftingUI()
	script.Parent.ImageLabel:TweenSizeAndPosition(UDim2.new(0, 851,0, 484), UDim2.new(0.081, 0,0.12, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .9, false)
end

local function CloseCraftingUI()
	script.Parent.ImageLabel:TweenSizeAndPosition(UDim2.new(0, 1,0, 1), UDim2.new(0.081, 0,0.12, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .9, false)
end

local function storebuttononclick()
	
	if not tweening then return end
	tweening = true
	v2 = not v2
	
	if not v2 then
		storebutton:TweenPosition(UDim2.new(-0.014, 0,0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false, Callback)
		storebutton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		script.Parent.ImageLabel.Visible = true
		OpenCraftingUI()
	elseif v2 then
		storebutton.BackgroundColor3 = Color3.fromRGB(0, 166, 249)
		CloseCraftingUI()
		storebutton:TweenPosition(UDim2.new(-0.014, 0,-0.134, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .1, false, Callback)
		script.Parent.ImageLabel.Visible = false
	end
end
storebutton.MouseButton1Click:Connect(storebuttononclick)

Try this when the tween is playing, try using this to detect when it’s playing also: TweenBase | Roblox Creator Documentation

Break