Animated TweenService Door

Learn how to make an Animated TweenService Door.

by rfviba

Author Avatar

Hello, Today I will show you how to make a door with TweenService.

So, for this tutorial I am going to use Vector3 Tween.

Let's get started.

First of all, We need to make a simple door.

I've made an example here:

img|80x45

After you made a door, Make sure all the parts of the door are anchored.

Like on the image:

img|80x45

Also, Don't forget to rename the parts and make sure the CanCollide in set ON.

After you've done that let's move on the scripting part.

Scripting

First we will localize TweenService and Door.

local Service = game:GetService("TweenService") --Localing TweenService
local Door = script.Parent.Parent.Door --Localing door

Now, We will create New TweenInfo.

local Info = TweenInfo.new(1.5) --number says how much seconds need to open door

After that We will make a MouseClick Function.

Before we start working on Function, Make sure the Button on your door has a ClickDetector and Script in it.

So, We will type in:

script.Parent.ClickDetector.MouseClick:Connect(function()--when mouse clicks the button
 script.Parent.CanCollide = false --disables cancollide so you can pass through doors
 local Change = {Position = Vector3.new(--your position here)} --tells door to move to that position

So, now I will help you with Vector3.

First Go to Home and then click on Move Tool.

img|15x5

Now you will select your door and move it to end.

img|80x45

img|80x45

Now when you moved your door to the end Go to Properties and copy the doors Position.

img|5x5

After you copied the Position click the Undo Button.

img|25x5

Then Paste your Position in the script here:

img|30x5

Now when you pasted it we are going to Create the Service and Play the Tween.

Type in:

 local Tween = Service:Create(Door, Info, Change)--creates TweenService
 Tween:Play()--plays tween
end)

And We are done with the Open Button Script.

Now The Close Button Script is ALMOST similar to the open script.

Make sure that your Close Button also has a ClickDetector and Script in it.

On the Close script just change the CanCollide and the position on the door.

So, now make sure that your door is closed like on the start example.

Again click on the door and Copy It's Position.

Change the Vector3 Position and put CanCollide = true in the script.

And you're...

DONE

I will make a whole open and close script down:

OPEN SCRIPT:

local Service = game:GetService("TweenService")--localing tweenservice
local Door = script.Parent.Parent.Door --localing door

local Info = TweenInfo.new(2)--number says how much seconds need to open the door

script.Parent.ClickDetector.MouseClick:Connect(function()--when mouse clicks the button
 script.Parent.CanCollide = false --disables cancollide so you can pass through doors
 local Change = {Position = Vector3.new(--your position here)} --tells door to go to that position

 local Tween = Service:Create(Door, Info, Change)--creates tweenservice
 Tween:Play()--plays tween
end)

CLOSE SCRIPT:

local Service = game:GetService("TweenService")--localing tweenservice
local Door = script.Parent.Parent.Door --localing door

local Info = TweenInfo.new(2)--number says how much seconds need to close door

script.Parent.ClickDetector.MouseClick:Connect(function()--when mouse clicks the button
 script.Parent.CanCollide = true --enables cancollide so you can't pass through doors
 local Change = {Position = Vector3.new(--your position here)} --tells door to go to that position

 local Tween = Service:Create(Door, Info, Change)--creates tweenservice
 Tween:Play()--plays tween
end)

That's It for this Tutorial.

Congrats, you've made your first animated door.

Thanks for viewing this tutorial.

Have a Nice Day. ;)

View in-game to comment, award, and more!