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