Vertical Sliding Door

So, I’ve looked around on the Developer Forum and I haven’t been able to find a proper solution to my door.

I’m trying to create a vertical sliding door. Which I’ve accomplished, however, the positioning of the door itself is completely off and I have no clue how to fix that. I am not overly experienced with CFrame or TweenServices.
See here:


image

Here is my script: (Again, I’m not experienced with this so there is bound to be a mistake)

db = true

script.Parent.ClickDetector.MouseClick:Connect(function()
	if db == true then
		db = false
		local door1 = script.Parent.Parent.door1
		local button = script.Parent
		button.BrickColor=button.Button.Value
		button.ClickDetector.MaxActivationDistance=0
		for i = 0.40, 2, 0.40 do
			door1.CFrame = CFrame.new(door1.CFrame.X, door1.CFrame.Y + i, door1.CFrame.Z)
			wait(0)
		end
		button.BrickColor=button.ButtonC.Value
		button.ClickDetector.MaxActivationDistance=30		
	else
		local door1 = script.Parent.Parent.door1
		local button = script.Parent
		db = true
		button.BrickColor=button.Button.Value
		button.ClickDetector.MaxActivationDistance=0
		for i = 0.40, 2, 0.40 do
			door1.CFrame = CFrame.new(door1.CFrame.X, door1.CFrame.Y - i, door1.CFrame.Z)
			
			wait(0)
		end
		button.BrickColor=button.ButtonO.Value
		button.ClickDetector.MaxActivationDistance=30
	end
end)

Thanks in advance.

1 Like

What about trying to use a Vector3.new because CFrame use and take the Actual facing direction and position of a 3D object.

for i = 0.40, 2, 0.40 do
	door1.Position = Vector3.new(door1.Position.X, door1.Position.Y + i, door1.Position.Z)
	wait(0)
end

Also, I recommend using TweenService for a smooth transition/sliding of something.

3 Likes

Perhaps you sould use TweenService for smooth sliding since it is easy to control the speed, the way it slides and the exact position you want it to slide to.

2 Likes

Thank you so much, that fixed my problem. How would I go about using TweenService if I ended up wanting a more smooth transition/sliding?

It would be like this:

local TweenService = game:GetService("TweenService")
local TweenSlideInfo = TweenInfo.new(
    1, -- Time (Duration)
    Enum.EasingStyle.Sine -- Animation type
    Enum.EasingDirection.Out -- Direction
    0, -- Repeat times. (0 = default || -1 = infinite)
    false, -- Play in reverse?
    0 -- Delay
)
local ClickDetector = script.Parent --Example only
local theActualDoor = workspace.door -- Example only

local DoorUp = TweenService:Create(taheActualDoor, TweenSlideInfo, {Position = Vector3.new(theActualDoor.Position.X, theActualDoor.Position.Y + 5, theActualDoor.Position.Z)})
local DoorDown = TweenService:Create(taheActualDoor, TweenSlideInfo, {Position = Vector3.new(theActualDoor.Position.X, theActualDoor.Position.Y - 5, theActualDoor.Position.Z)})

local isOpen = false -- Toggle
ClickDetector.MouseClick:Connect(function(theClicker))
    if not isOpen then
        DoorUp:Play()
        DoorUp.Completed:Wait()
        isOpen = true
    else
        DoorDown:Play()
        DoorDown.Completed:Wait()
        isOpen = false
    end
end)


You can modify this by searching in the Developer Hub

1 Like

Alright, I will play around with this. Thank you again for the help!

1 Like