#door system not working

1 messages · Page 1 of 1 (latest)

random rover
#
local doorModel = script.Parent.Parent

local hitbox = script.Parent
local doorbase = doorModel.DoorBase


local hinge1 = doorModel.Hinge1
local hinge1pos = hinge1.Position
local hingeCFrame = CFrame.new(hinge1pos)



local ts = game:GetService("TweenService")
local ti = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 1)

local doorOpen = false

local function rotateDoor(degrees)
    local currentCFrame = doorbase.CFrame
    
    local finalCFrame = hinge1.CFrame * CFrame.Angles(0, math.rad(degrees), 0)
    
    local goal = { CFrame = finalCFrame }
    local tween = ts:Create(doorbase, ti, goal)
    tween:Play()
    tween.Completed:Wait()
end

local function openDoor()

    rotateDoor(90)
end

local function closeDoor()
    
    rotateDoor(-90)
    
end

hitbox.Touched:Connect(function()
    if doorOpen == false then
        
        doorOpen = true
        openDoor()

    end
end)

hitbox.TouchEnded:Connect(function()
    if doorOpen == true then
        
        doorOpen = false
        closeDoor()
        
    end
end)