I am learning Lua and decided to try and make a lift as to better my understanding of tweening. The lift itself was fairly easy, although I’m sure I could have achieved a similar outcome with less code. The problem was with the doors. The doors should open when the lift reaches its destination. At the moment the doors don’t move. Any suggestions as to how I can generally improve my code would also be great.
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Lift = script.Parent
local LiPos = Lift.Position
local DURATION = 4
local Door11 = game.Workspace.Door11
local Door12 = game.Workspace.Door12
local Door21 = game.Workspace.Door21
local Door22 = game.Workspace.Door22
local Door31 = game.Workspace.Door31
local Door32 = game.Workspace.Door32
local CD1 = game.Workspace.Part1.ClickDetector
local CD2 = game.Workspace.Part2.ClickDetector
local CD3 = game.Workspace.Part3.ClickDetector
local Door1Open = false
local Door2Open = false
local Door3Open = false
local Tweenfo = TweenInfo.new(
3,
Enum.EasingStyle.Sine,
Enum.EasingDirection.In,
0,
false,
0
)
local Goals1 =
{
Position = Vector3.new(0,0,0)
}
local Goals2 =
{
Position = Vector3.new(0,15,0)
}
local Goals3 =
{
Position = Vector3.new(0,30,0)
}
local TweenLift1 = TweenService:Create(Lift, Tweenfo, Goals1)
local TweenLift2 = TweenService:Create(Lift, Tweenfo, Goals2)
local TweenLift3 = TweenService:Create(Lift, Tweenfo, Goals3)
CD1.MouseClick:Connect(function()
if Door1Open == true or Door2Open == true or Door3Open == true then
Door1Open = false
Door2Open = false
Door3Open = false
end
TweenLift1:Play()
TweenLift1.Completed:Connect(function()
Door1Open = true
end)
end)
CD2.MouseClick:Connect(function()
if Door1Open == true or Door2Open == true or Door3Open == true then
Door1Open = false
Door2Open = false
Door3Open = false
end
TweenLift2:Play()
TweenLift2.Completed:Connect(function()
Door2Open = true
end)
end)
CD3.MouseClick:Connect(function()
if Door1Open == true or Door2Open == true or Door3Open == true then
Door1Open = false
Door2Open = false
Door3Open = false
end
TweenLift3:Play()
TweenLift3.Completed:Connect(function()
Door3Open = true
end)
end)
local function doorFunc()
if Door1Open == true then
Door11.CFrame = Door11.CFrame*CFrame.new(0,0,-5)
Door12.CFrame = Door12.CFrame*CFrame.new(0,0,5)
else
Door11.CFrame = Door11.CFrame*CFrame.new(0,0,5)
Door12.CFrame = Door12.CFrame*CFrame.new(0,0,-5)
end
if Door2Open == true then
Door21.CFrame = Door21.CFrame*CFrame.new(0,0,-5)
Door22.CFrame = Door22.CFrame*CFrame.new(0,0,5)
else
Door21.CFrame = Door21.CFrame*CFrame.new(0,0,5)
Door22.CFrame = Door22.CFrame*CFrame.new(0,0,-5)
end
if Door3Open == true then
Door31.CFrame = Door31.CFrame*CFrame.new(0,0,-5)
Door32.CFrame = Door32.CFrame*CFrame.new(0,0,5)
else
Door31.CFrame = Door31.CFrame*CFrame.new(0,0,5)
Door32.CFrame = Door32.CFrame*CFrame.new(0,0,-5)
end
end
doorFunc()