I have successfully made a door using tweenservice. The problem is that I do not know how to prevent users from spamming the door open and closed. I would like to know how exactly would I make it so there is a delay and the user is not able to spam the door. So far, the debounce boolean I made does not work. Script:
local Door = script.Parent.Door
local debounce = false
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local DoorOpen = {CFrame = Door.CFrame + Door.CFrame.lookVector * 6}
local DoorClose = {CFrame = Door.CFrame }
local open = TS:Create(Door, TI, DoorOpen)
local close = TS:Create(Door, TI, DoorClose)
local sound = script.Parent["BMRF Sliding Door Open"]
local closesound = script.Parent["BMRF Sliding Door Close"]
script.Parent.ToggleDoor.OnServerEvent:Connect(function()
if debounce == false then
debounce = true
sound:Play()
open:Play()
elseif debounce == true then
debounce = false
closesound:Play()
close:Play()
end
end)

1 comment
Your right! But just a note, if you want a better wait, you can yield until the sound and the open sound ends.