Greetings!
I made this door system where the door opens, and it fades and then teleports you into the place.
Here is a video demonstration:
However, I think my code is pretty iffy.
I have to duplicate everything for both the outside door and Inside door.
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local DoorOpening = TweenInfo.new(1.4, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false)
local Doors = CollectionService:GetTagged("Doors")
for _, Door in Doors do
Door.Touched.Touched:Connect(function(Part)
local Humanoid = Part.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
local Player = Players:GetPlayerFromCharacter(Part.Parent)
if Player then
if not Player:GetAttribute("UsingDoor") then
Player:SetAttribute("UsingDoor", true)
local StarterDoorOpenedValue = Instance.new("CFrameValue")
local TeleportDoorOpenedValue = Instance.new("CFrameValue")
local TeleportDoor = Door.TeleportDoor.Value
StarterDoorOpenedValue.Value = Door.Door2:GetPivot()
TeleportDoorOpenedValue.Value = TeleportDoor.Door1:GetPivot()
local Tween = TweenService:Create(StarterDoorOpenedValue, DoorOpening, {Value = Door.Door2.WorldPivot * CFrame.Angles(0, math.rad(-90), 0)})
local Tween2 = TweenService:Create(TeleportDoorOpenedValue, DoorOpening, {Value = TeleportDoor.Door1.WorldPivot * CFrame.Angles(0, math.rad(90), 0)})
local DoorChanged = StarterDoorOpenedValue.Changed:Connect(function()
Door.Door2:PivotTo(StarterDoorOpenedValue.Value)
end)
local TeleportDoorChanged = TeleportDoorOpenedValue.Changed:Connect(function()
TeleportDoor.Door1:PivotTo(TeleportDoorOpenedValue.Value)
end)
Tween:Play()
Tween2:Play()
Door.DoorTop.DoorOpen:Play()
TeleportDoor.DoorTop.DoorOpen:Play()
task.spawn(function()
Tween.Completed:Wait()
Door.DoorTop.ExtraSound:Play()
TeleportDoor.DoorTop.ExtraSound:Play()
end)
task.delay(1, function()
ReplicatedStorage.Fade:FireClient(Player, true)
task.wait(0.5)
Player.Character:PivotTo(Door.TeleportDoor.Value.TeleportPart.CFrame)
ReplicatedStorage.Fade:FireClient(Player, false)
local ClosingTween = TweenService:Create(StarterDoorOpenedValue, DoorOpening, {Value = Door.Door2.WorldPivot * CFrame.Angles(0, math.rad(90), 0)})
local ClosingTween2 = TweenService:Create(TeleportDoorOpenedValue, DoorOpening, {Value = TeleportDoor.Door1.WorldPivot * CFrame.Angles(0, math.rad(-90), 0)})
ClosingTween:Play()
ClosingTween2:Play()
ClosingTween.Completed:Wait()
Door.DoorTop.DoorClose:Play()
TeleportDoor.DoorTop.DoorClose:Play()
Player:SetAttribute("UsingDoor", false)
end)
end
end
end
end)
end
If you can help make this better, that would be great.
Sincerely, Will