I’ve made a door script but for some reason debouncing won’t work, any help?
--// Services
local ReplStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
--// Events
local hasInteracted = ReplStorage.Events:WaitForChild("hasInteracted")
--// Door
local hinge = script.Parent
local door = hinge.Parent
local clickDetector = door.ClickDetector
--// IsClosed
local locked = false
local isOpen = false
local debounce = false
--// Tweening
local Info = TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local open = {
CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(-90),0)}
local close = {
CFrame = hinge.CFrame * CFrame.Angles(0,0,0)}
local doorOpen = TweenService:Create(hinge, Info, open)
local doorClose = TweenService:Create(hinge, Info, close)
--// Functions
local function Clicked(player)
print(player.Name.." Interacted: "..door.Name)
if locked then
if debounce then return end
debounce = true
hasInteracted:FireClient(player, locked)
debounce = false
elseif not locked then
if debounce then return end
debounce = true
if isOpen == false then
doorOpen:Play()
isOpen = true
debounce = false
else
doorClose:Play()
isOpen = false
debounce = false
end
end
end
clickDetector.MouseClick:Connect(Clicked)
EDIT: I’ve tried stuff like these before posting so they won’t work either:
if locked then
if debounce then return end
end
--or
if locked and not debounce then
end