Re-sizing Sliding Door Tween

Trying to make a simple sliding door tween, but I want to instead have the parts just resize themselves to split down the middle and fit to the edge. I don’t want to just slide them to the side, but for now, this is what I have →

https://gyazo.com/4310ad7c36f779fe26fe9f006974cde9

Essential Question: How can I make the doors split down the middle, and resize instead of just moving CFrame?

Code →

local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1)

local PartA = script.Parent.Parent.PartA
local PartB = script.Parent.Parent.PartB

--[[ DOOR ]]--

local leftGoalOpen = {}
local leftGoalClose = {}
leftGoalOpen.CFrame = PartA.CFrame * CFrame.new(PartA.Size.X, 0,0)
leftGoalClose.CFrame = PartA.CFrame
local leftTweenOpen = TweenService:Create(PartA, tweenInfo, leftGoalOpen)
local leftTweenClose = TweenService:Create(PartA, tweenInfo, leftGoalClose)

local rightGoalOpen = {}
local rightGoalClose = {}
rightGoalOpen.CFrame = PartB.CFrame * CFrame.new(-PartB.Size.X, 0,0)
rightGoalClose.CFrame = PartB.CFrame
local rightTweenOpen = TweenService:Create(PartB, tweenInfo, rightGoalOpen)
local rightTweenClose = TweenService:Create(PartB, tweenInfo, rightGoalClose)

local sound = script.Parent.Sound

--[[ FUNCTION ]]--

local DoorOpening = false

script.Parent.ProximityPrompt.Triggered:Connect(function()

	if DoorOpening == false then
		
		rightTweenOpen:Play()
		leftTweenOpen:Play()
		sound:Play()
		wait(2)
		script.Parent.ProximityPrompt.ObjectText = "Close"
		DoorOpening = true
		
	else
		
		rightTweenClose:Play()
		leftTweenClose:Play()
		sound:Play()
		wait(2)
		script.Parent.ProximityPrompt.ObjectText = "Open"
		DoorOpening = false
		
	end
	
	
end)
1 Like

You can also change the size of the part using the same tween, but you will need to change the position of the door to account for the size change (preferably in the XVector of the CFrame multiplied by half the part’s X size).

Add Size to your goals.

So for example:

leftGoalOpen.Size = partA.Size * Vector3.new(0,1,1)
leftGoalClose.Size = partA.Size
-- also
rightGoalOpen.Size = partB.Size * Vector3.new(0,1,1)
rightGoalClose.Size = partB.Size

This way when you tween the parts, it will not only tween the CFrame, but it will also tween the Size.

2 Likes

This seems to do the trick!

Though…

https://gyazo.com/935e9aaf7bd36de1bc87473eb0225613

How would I change the CFrame position to match exactly just where the part ends originally? (To not go past/through the gate)

Set the goal CFrame offset to half the size, not the whole size.

leftGoalOpen.CFrame = PartA.CFrame * CFrame.new(PartA.Size.X*.5, 0,0)
rightGoalOpen.CFrame = PartB.CFrame * CFrame.new(-PartB.Size.X*.5, 0,0)
3 Likes

5215248500.rbxm (5.7 KB)
Here’s an example.

1 Like