Hello ! I would like my garage door to close automatically after 5 seconds of the player opening the door and to be able to open it again using “proximityprompt”
therefore the player would no longer be able to close the door but just open it.
local frame = script.Parent
local Frame = game.Workspace.DoorGarage.DoorFrame
local openSound = frame:WaitForChild("DoorOpen")
local closeSound = frame:WaitForChild("DoorClose")
local proximityprompt = Frame:WaitForChild("ProximityPrompt")
local model = frame.Parent
local frameClose = model:WaitForChild("Door-Close")
local frameOpen = model:WaitForChild("Door-Open")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")
local debounce = true
proximityprompt.Triggered:Connect(function()
if debounce == true then
debounce = false
if opened.Value == true then
opened.Value = false
closeSound:Play()
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
else
opened.Value = true
openSound:Play()
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
end
wait(.35)
debounce = true
end
end)
function CloseDoor()
if (opened.Value == true) then
opened.Value = false
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
closeSound:Play()
end
end
function OpenDoor()
if (opened.Value == false) then
opened.Value = true
task.delay(5,CloseDoor)
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
openSound:Play()
end
end
local debounce = true
proximityprompt.Triggered:Connect(function()
if debounce == true then
debounce = false
if opened.Value == true then
CloseDoor()
else
OpenDoor()
end
task.wait(.35)
debounce = true
end
end)
A Good way would be to calculate the time since an event happened, then fire the event when the condition is met, it doesnt require a separate thread or yielding to do so.
I succeeded, but you have to press E twice to be able to open again… any idea?
local frame = script.Parent
local Frame = game.Workspace.DoorGarage.DoorFrame
local openSound = frame:WaitForChild("DoorOpen")
local closeSound = frame:WaitForChild("DoorClose")
local proximityprompt = Frame:WaitForChild("ProximityPrompt")
local model = frame.Parent
local frameClose = model:WaitForChild("Door-Close")
local frameOpen = model:WaitForChild("Door-Open")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")
local debounce = true
proximityprompt.Triggered:Connect(function()
if debounce == true then
debounce = false
if opened.Value == true then
opened.Value = false
else
opened.Value = true
openSound:Play()
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
wait(2)
closeSound:Play()
tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
end
wait(.35)
debounce = true
end
end)