Hello guys,
So in my horror game, I want the doors to go back to being closed a few seconds after it being opened. I’m not experienced in scripting to a pro level but I got some working code here that manages to make the door open with tween service, how do I make it go back to its closed state?
local frame = script.Parent
local openSound = frame:WaitForChild(“DoorOpen”)
local closeSound = frame:WaitForChild(“DoorClose”)
local clickDetector = frame:WaitForChild(“ClickDetector”)
local model = frame.Parent
local frameClose = model:WaitForChild(“DoorFrameClose”)
local frameOpen = model:WaitForChild(“DoorFrameOpen”)
local opened = model:WaitForChild(“Opened”)
local tweenService = game:GetService(“TweenService”)
local debounce = true
clickDetector.MouseClick:Connect(function()
if debounce == true then
debounce = false
if opened.Value == true then
opened.Value = false
closeSound:Play()
tweenService:Create(frame,TweenInfo.new(0.28),{CFrame = frameClose.CFrame}):Play()
else
opened.Value = true
openSound:Play()
tweenService:Create(frame,TweenInfo.new(0.28),{CFrame = frameOpen.CFrame}):Play()
end
wait(.35)
debounce = false
end
end)