Door Script still plays sound when you click button

When you click on the button, it opens, then when you click the button but you didn’t wait for the cooldown, it still makes the noise.

Here is the script
– Door + Positions
local door = script.Parent.Door

local button = script.Parent.Button.Button

local posY = script.Parent.Pos1.Position

local posX = script.Parent.Pos2.Position

local debounce = true

local debounce2 = true

local doorSound = script.Parent.SlidingDoor

-- Tween

local tweenService = game:GetService("TweenService")

local tweenCreateX = tweenService:Create(door,TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Position = posX})

local tweenCreateY = tweenService:Create(door,TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Position = posY})

button.ClickDetector.MouseClick:Connect(function(player)

if debounce == true then

debounce = false

tweenCreateX:Play()

doorSound:Play()

wait(2)

button.ClickDetector.MouseClick:Connect(function()

tweenCreateY:Play()

doorSound:Play()

end)

debounce = true

end

end)

I really wouldn’t encase your MouseClick events inside of each other, that would just make it fire twice after the first time

local door = script.Parent.Door
local button = script.Parent.Button.Button
local posY = script.Parent.Pos1.Position
local posX = script.Parent.Pos2.Position

local debounce = false
local debounce2 = true
local doorSound = script.Parent.SlidingDoor

-- Tween
local tweenService = game:GetService("TweenService")
local tweenCreateX = tweenService:Create(door,TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Position = posX})
local tweenCreateY = tweenService:Create(door,TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.In),{Position = posY})

button.ClickDetector.MouseClick:Connect(function(player)
    if debounce == false then
        debounce = true

        tweenCreateX:Play()
        doorSound:Play()
        wait(2)

        debounce2 = false

    elseif debounce2 == false then
        debounce2 = true

        tweenCreateY:Play()
        doorSound:Play()
        wait(2)

        debounce = false
    end
end)
2 Likes