Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I stop my door from rotating?

Asked by 5 years ago

I have this door that I want to work on TweenService, it works fine when it isn't rotated, but when I rotate the model to any direction other than the original orientation, the door will spin upon moving, how do I fix this?

TweenService = game:GetService("TweenService")

doorOpen = script.Parent.DoorOpen
doorClose = script.Parent.DoorClose
local reader1 = script.Parent.KeycardReader1.Slot
reader2 = script.Parent.KeycardReader2.Slot
screen1 = script.Parent.Screen1
screen2 = script.Parent.Screen2
granted = script.Parent.AGranted

local clearanceLevels = {
    " [SCP]  Card-L1",
    "[SCP] Card-L2",
    "[SCP] Card-Omni"
}

door = script.Parent.MainDoor

local openTween = TweenService:Create(
        door,
        TweenInfo.new(1.72),
        {CFrame = CFrame.new(
            door.Position.X, 
            door.Position.Y + door.Size.Y, 
            door.Position.Z)}

)

local closeTween = TweenService:Create(
        door,
        TweenInfo.new(1.52),
        {CFrame = door.CFrame}
)

function handleDoor()
    screen1.Color = Color3.new(0,255/255,255/255)
    screen2.Color = Color3.new(0,255/255,255/255)
    openTween:Play()
    doorOpen:Play()
    wait(5)
    screen1.Color = Color3.new(0,0,0)
    screen2.Color = Color3.new(0,0,0)
    closeTween:Play()
    doorClose:Play()
    wait(2)
end

local function checkClearanceLevel(level)
    for _, v in ipairs(clearanceLevels) do
        if level == v then
            return true
        end
    end
    return false
end

local debounce = false
reader1.Touched:Connect(function(hit)
    if debounce then return end
    if hit.Name == "Handle" and checkClearanceLevel(hit.Parent.Name) then
        debounce = true
        granted:Play()
        handleDoor()
        debounce = false
    end
end)

local debounce = false
reader2.Touched:Connect(function(hit)
    if debounce then return end
    if hit.Name == "Handle" and checkClearanceLevel(hit.Parent.Name) then
        debounce = true
        granted:Play()
        handleDoor()
        debounce = false
    end
end)

I hope I can get this fixed soon.

0
add comments and label the error Wicked_Wlzard 110 — 5y
0
please label errors or nobody will spend a lot of time reading your entire script SCP774 191 — 5y

1 answer

Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
5 years ago

If you just set a new CFrame instead of translating the current CFrame, it will be in world space, so when you don't rotate the door by its own orientation, it rotates it back to (0,0,0). Instead of setting a new CFrame, you should add the door's size to the door's current CFrame, so the door will keep its orientation.

local openTween = TweenService:Create(
    door,
    TweenInfo.new(1.72),
    {CFrame = door.CFrame + Vector3.new(0,door.Size.Y,0))}
)
0
This works perfectly, thank you. marltonjohnson9876 11 — 5y
Ad

Answer this question