#Advanced door system for no reason

1 messages · Page 1 of 1 (latest)

exotic tendon
#

Can someone help me with my door system which is complicated for no reason

local Functions = require(game.ServerScriptService.Functions)

-- Services
local CS = game:GetService("CollectionService")
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")

-- Interact
local RemoteEvent = RS:WaitForChild("RemoteEvents")
local DoorInteract = RemoteEvent:WaitForChild("DoorInteract")
local DoorInteractDouble = RemoteEvent:WaitForChild("DoorInteractDouble")

-- Store original CFrames
local originalCFrames = {}

-- Prompt
DoorInteract.OnServerEvent:Connect(function(player, doorName, side)

local DoorModel = workspace.Doors:FindFirstChild(doorName)

    local Door = DoorModel:WaitForChild("Door")
    
    local Lock = Door.Lock
    local Locks = Door.Locks

    local DoorSide = side
    local Frame = DoorModel.Frame

    if not originalCFrames[Door] then originalCFrames[Door] = Door:GetPivot() end
    local originalCFrame = originalCFrames[Door]

    local targetCFrame = originalCFrame * CFrame.Angles(0, math.rad(-95aaa), 0)

    if DoorSide == "L" then
        targetCFrame = originalCFrame * CFrame.Angles(0, math.rad(95), 0)
    end

    if DoorSide == "R" then
        targetCFrame = originalCFrame * CFrame.Angles(0, math.rad(-95), 0)
    end

    local IsOpen = Door.IsOpen
    local IsLocked = Door.IsLocked
    
    if Locks.Value == 0 then
        IsLocked.Value = false
    else
        IsLocked.Value = true
    end

    if IsLocked == false then
        if IsOpen.Value == false then
            Functions.RotateDoor(Door, targetCFrame, 0.5)
            IsOpen.Value = true
        else
            Functions.RotateDoor(Door, originalCFrame, 0.5)
            IsOpen.Value = false

        end
    end

end)

#

-- Services
local CS = game:GetService("CollectionService")
local RS = game:GetService("ReplicatedStorage")

-- Variables
local RemoteEvents = RS:WaitForChild("RemoteEvents")
local DoorInteract = RemoteEvents:WaitForChild("DoorInteract")

-- Modules
local LocalFunctions = require(game.ReplicatedFirst.LocalModules.LocalFunctions)

-- Hook existing tagged prompts
for _, prompt in CS:GetTagged("DoorPrompt") do
LocalFunctions.hookPrompt(prompt)
end

-- Hook prompts tagged later
CS:GetInstanceAddedSignal("DoorPrompt"):Connect(function(prompt)
LocalFunctions.hookPrompt(prompt)
end)

function Functions.LerpRotator(A,B,Alpha)
return A:Lerp(B, Alpha)
end

function Functions.EaseCubicInOut(T)
return T < 0.5
and 4 * T * T * T
or 1 - (-2 * T + 2)^3 / 2
end

function Functions.RotateDoor(door, B, duration)
local A = door:GetPivot()
local elapsed = 0
local connection
connection = RunService.Heartbeat:Connect(function(dt)
elapsed = elapsed + dt
local T = math.clamp(elapsed / duration, 0, 1)
local Alpha = Functions.EaseCubicInOut(T)
door:PivotTo(Functions.LerpRotator(A, B, Alpha))
door.CanCollide = false
if T >= 1 then
door.CanCollide = true
door:PivotTo(B)
connection:Disconnect()
end
end)
return connection
end

return Functions

-- Services
local RS = game:GetService("ReplicatedStorage")
local CS = game:GetService("CollectionService")

-- Variables
local RemoteEvents = RS:WaitForChild("RemoteEvents")
local DoorInteract = RemoteEvents:WaitForChild("DoorInteract")

local Functions = {}

function Functions.hookPrompt(prompt)
local doorName = prompt:GetAttribute("DoorName")
local side = prompt:GetAttribute("DoorSide")

prompt.Triggered:Connect(function()
    DoorInteract:FireServer(doorName, side)
end)

end

return Functions

#

How it works: It doesnt use tweens instead it rotates the pivot with a "Custom" Lerp rotator also trying to make functionality for locking but it doesnt work