Help Needed Tweening a Door

Hello, I am going to get right to the issue I am having with my door script. So I have this door set to open when you touch it but I am having trouble with the tween side of things and would really appreciate some help thanks. (Please keep in mind I’m pretty new to Lua)

Here is my Script -

local Tween_Service = game:GetService("TweenService")

local Door = script.Parent.Door.DoorMain
local KeyArea1 = script.Parent.KeycardReader1.KeycardReader
local KeyArea2 = script.Parent.KeycardReader2.KeycardReader

local Cooldown = false

local TI = TweenInfo.new(
   5,
   Enum.EasingStyle.Sine,
   Enum.EasingDirection.In,
   0,
   false,
   0
)

local DoorOpen = Tween_Service:Create(Door, TI, Door.CFrame.LookVector)
local DoorClose = Tween_Service:Create(Door, TI, Door.CFrame.LookVector * 5)

local function OpenDoor()
   DoorOpen:Play()
   wait(3)
   DoorClose:Play()
end

Door.Touched:Connect(OpenDoor())

Could you show a demonstration of how they are currently operating

It doesn’t operate at all, it does nothing when you touch the door.

Have you tried looking at the output

It says it is “Unable to Cast to Dictionary”.

Yup, I see the problem here, so basically your not actually using the last argument of tween service right, it has to be a table then what you want to tween

EDIT : Replace door close and open with these lines of code

local DoorOpen = Tween_Service:Create(Door, TI, {CFrame = Door.CFrame + Door.CFrame.LookVector})
local DoorClose = Tween_Service:Create(Door, TI, {CFrame = Door.CFrame + Door.CFrame.LookVector * 15})

@Aensvey

I know your suppose to put a Vector3 position where “Door.CFrame.LookVector” is but I’m trying to have the door be copyable because if I had a set position and moved the door it would be the wrong position for the new door.

I updated my recent reply check it out.

Just a heads up, this will not work and only cause the door to move in one singular direction. Regardless of if it is opening or closing. The lookvector represents the direction the CFrame is facing as a unit vector in 3d space.

You should use something like CFrame = Door.CFrame * CFrame.new(5,0,0) for the opening, and CFrame = Door.CFrame * CFrame.new(-5,0,0) for the closing (you might need to edit this).

A better idea, though, would be to have set CFrames for the opening and closing, which would be to define variables as follows:

local openCFrame = Door.CFrame
local closedCFrame = Door.CFrame * CFrame.new(5,0,0) -- You might need to change which axis this is on

then, having tweens for opening and closing the door:

local DoorOpen = Tween_Service:Create(Door, TI, {CFrame = doorOpen})
local DoorClose = Tween_Service:Create(Door, TI, {CFrame = doorClosed})

Additionally, when it says:

it should be changed to Door.Touched:Connect(OpenDoor), removing the function call and changing it to a function to call when the door is touched.

Well I just converted his code to working code

It doesn’t work, it says it is expecting a Vector3 Value.

Show the output please
30chars

image

Ohhhh I see now try replace DoorClose with this line

local DoorClose = Tween_Service:Create(Door, TI, {CFrame = Door.CFrame + Door.CFrame.LookVector + Vector3.new(0,0,Door.CFrame.LookVector * 15)})

When I pressed play to try it, the door was moved slightly in front of the door frame but when I touched it still nothing happened.

Check out my reply, it explains this pretty well.

Thank you both for your help, it is now working!!!

I have a side question how do you get these roles by your name like Programmer & Builder?

Check out this post: https://devforum.roblox.com/t/how-would-i-get-one-of-these-custom-tags-in-my-devforum-profile-name/142876/2

Says it doesn’t exist or it is private.

1 Like