Button Doesn't Wait for Cooldown

I set up a cooldown for this button but it doesn’t work. When I press it, the “Open” value inside of the button turns to true, and the button is only allowed to be clicked again once “Open” = false. It does set it to true but the button doesn’t wait for it to turn false, it just lets you click it again.

local Ready = false

local ObjectsToTween1 = {script.Parent.Parent.Background1, script.Parent.Parent.Weapons, script.Parent.Parent.Shop}

script.Parent.MouseButton1Up:Connect(function()
	if Ready == false and script.Parent.Parent.Open.Value == false then
		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.35, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundColor3 = Color3.fromRGB(41, 206, 74)}):Play()
		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.35, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {TextColor3 = Color3.fromRGB(255, 255, 255)}):Play()
		
		script.Parent:TweenSize(UDim2.new(0, 145, 0, 70), "InOut", "Quint", 0.35)
		script.Parent:TweenPosition(UDim2.new(0.5, 0, 0.948, 0), "InOut", "Quint", 0.35)
		
		script.Parent.Parent.Background1:TweenPosition(UDim2.new(0.421, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Weapons:TweenPosition(UDim2.new(0.421, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Shop:TweenPosition(UDim2.new(0.443, 0, 0.927, 0), "InOut", "Quint", 0.35)
		
		script.Parent.Parent.Background2:TweenPosition(UDim2.new(0.534, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Profile:TweenPosition(UDim2.new(0.534, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Settings:TweenPosition(UDim2.new(0.556, 0, 0.927, 0), "InOut", "Quint", 0.35)
		
		game.Workspace.Sound.Click:Play()
		
		wait(0.35)
		
		Ready = true
		script.Parent.Parent.Open.Value = true
	elseif Ready == true and script.Parent.Parent.Open.Value == true then
		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.35, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {BackgroundColor3 = Color3.fromRGB(222, 222, 222)}):Play()
		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.35, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {TextColor3 = Color3.fromRGB(0, 0, 0)}):Play()
		
		script.Parent:TweenSize(UDim2.new(0, 133, 0, 64), "InOut", "Quint", 0.35)
		script.Parent:TweenPosition(UDim2.new(0.5, 0, 0.948, 0), "InOut", "Quint", 0.35)
		
		script.Parent.Parent.Background1:TweenPosition(UDim2.new(0.424, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Weapons:TweenPosition(UDim2.new(0.424, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Shop:TweenPosition(UDim2.new(0.446, 0, 0.927, 0), "InOut", "Quint", 0.35)

		script.Parent.Parent.Background2:TweenPosition(UDim2.new(0.532, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Profile:TweenPosition(UDim2.new(0.532, 0, 0.927, 0), "InOut", "Quint", 0.35)
		script.Parent.Parent.Settings:TweenPosition(UDim2.new(0.554, 0, 0.927, 0), "InOut", "Quint", 0.35)
		
		game.Workspace.Sound.Click:Play()
		
		wait(0.35)

		Ready = false
		script.Parent.Parent.Open.Value = false
	end
end)

You have a .35 second window where open is not true and you can click it again.

wait(0.35)
		
Ready = true
script.Parent.Parent.Open.Value = true

maybe try

script.Parent.Parent.Open.Value = true

wait(0.35)	

Ready = true

Thank you so much, that really helps!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.