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.
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))} )