This video will cover all you need to make fully function Roblox doors in Roblox Studio using TweenService.
Script for single/sliding door:
local TweenService = game:GetService("TweenService")
local TweenInfoDoorOpen = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
local TweenInfoDoorClose = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local Door = script.Parent:WaitForChild("Door")
local DoorButton = Door:WaitForChild("ProximityPrompt")
local IsOpen = false
local OpenGoal = {}
OpenGoal.CFrame = script.Parent:WaitForChild("DoorOpenPosition").CFrame
local CloseGoal = {}
CloseGoal.CFrame = script.Parent:WaitForChild("DoorClosePosition").CFrame
local TweenOpen = TweenService:Create(Door, TweenInfoDoorOpen, OpenGoal)
local TweenClose = TweenService:Create(Door, TweenInfoDoorClose, CloseGoal)
DoorButton.Triggered:Connect(function()
if IsOpen == false then -- Try to Open
DoorButton.Enabled = false
IsOpen = true
TweenOpen:Play()
TweenOpen.Completed:Wait()
DoorButton.ActionText = "Close"
DoorButton.Enabled = true
else -- Try to Close
DoorButton.Enabled = false
IsOpen = false
TweenClose:Play()
TweenClose.Completed:Wait()
DoorButton.ActionText = "Open"
DoorButton.Enabled = true
end
end)
Script for double door:
local TweenService = game:GetService("TweenService")
local TweenInfoDoorOpen = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
local TweenInfoDoorClose = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local LeftDoor = script.Parent:WaitForChild("LeftDoor")
local RightDoor = script.Parent:WaitForChild("RightDoor")
local DoorButton = RightDoor:WaitForChild("ProximityPrompt")
local IsOpen = false
local LeftOpenGoal = {}
LeftOpenGoal.CFrame = script.Parent:WaitForChild("LeftDoorOpenPosition").CFrame
local LeftCloseGoal = {}
LeftCloseGoal.CFrame = script.Parent:WaitForChild("LeftDoorClosePosition").CFrame
local RightOpenGoal = {}
RightOpenGoal.CFrame = script.Parent:WaitForChild("RightDoorOpenPosition").CFrame
local RightCloseGoal = {}
RightCloseGoal.CFrame = script.Parent:WaitForChild("RightDoorClosePosition").CFrame
local TweenOpenLeft = TweenService:Create(LeftDoor, TweenInfoDoorOpen, LeftOpenGoal)
local TweenCloseLeft = TweenService:Create(LeftDoor, TweenInfoDoorClose, LeftCloseGoal)
local TweenOpenRight = TweenService:Create(RightDoor, TweenInfoDoorOpen, RightOpenGoal)
local TweenCloseRight = TweenService:Create(RightDoor, TweenInfoDoorClose, RightCloseGoal)
DoorButton.Triggered:Connect(function()
if IsOpen == false then -- Try to Open
DoorButton.Enabled = false
IsOpen = true
TweenOpenLeft:Play()
TweenOpenRight:Play()
TweenOpenRight.Completed:Wait()
DoorButton.ActionText = "Close"
DoorButton.Enabled = true
else -- Try to Close
DoorButton.Enabled = false
IsOpen = false
TweenCloseLeft:Play()
TweenCloseRight:Play()
TweenCloseRight.Completed:Wait()
DoorButton.ActionText = "Open"
DoorButton.Enabled = true
end
end)
Script for automatic door:
local WaitTime = 3
local TweenService = game:GetService("TweenService")
local TweenInfoDoorOpen = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
local TweenInfoDoorClose = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
local LeftDoor = script.Parent:WaitForChild("LeftDoor")
local RightDoor = script.Parent:WaitForChild("RightDoor")
local DoorButton = script.Parent:WaitForChild("TouchPart")
local IsOpen = false
local LeftOpenGoal = {}
LeftOpenGoal.CFrame = script.Parent:WaitForChild("LeftDoorOpenPosition").CFrame
local LeftCloseGoal = {}
LeftCloseGoal.CFrame = script.Parent:WaitForChild("LeftDoorClosePosition").CFrame
local RightOpenGoal = {}
RightOpenGoal.CFrame = script.Parent:WaitForChild("RightDoorOpenPosition").CFrame
local RightCloseGoal = {}
RightCloseGoal.CFrame = script.Parent:WaitForChild("RightDoorClosePosition").CFrame
local TweenOpenLeft = TweenService:Create(LeftDoor, TweenInfoDoorOpen, LeftOpenGoal)
local TweenCloseLeft = TweenService:Create(LeftDoor, TweenInfoDoorClose, LeftCloseGoal)
local TweenOpenRight = TweenService:Create(RightDoor, TweenInfoDoorOpen, RightOpenGoal)
local TweenCloseRight = TweenService:Create(RightDoor, TweenInfoDoorClose, RightCloseGoal)
DoorButton.Touched:Connect(function(who)
if who and who.Parent and who.Parent:FindFirstChild("Humanoid") then
if IsOpen == false then
IsOpen = true
TweenOpenLeft:Play()
TweenOpenRight:Play()
TweenOpenRight.Completed:Wait()
wait(WaitTime)
TweenCloseLeft:Play()
TweenCloseRight:Play()
TweenCloseRight.Completed:Wait()
IsOpen = false
end
end
end)