So this lift that we made isn’t working. What it’s supposed to do is open the double doors, then go down to the desired location, stop, and open the doors again. How we are trying to do this is using a BodyVector to make the elevator travel downwards. However the lift must be unanchored for this to happen. So when it’s at the top/bottom, we anchor it, destroy the welds in the doors, open/close the doors, create new welds, unanchor the lift, go down, and repeat. However there are two problems. The lift does a sort of free fall, and after the doors close, the door parts are positioned in the middle of the car like this.
I think this is a problem with the Weld.C0 and Weld.C1 properties, but I have no idea how they work. Here is the main lift script (the one that actually gets it to move)
local bodyvelocity = script.Parent.LiftCar.VertHeight.BodyVelocity
local doorvalue = script.Parent.Dooropen
local liftParts = script.Parent:GetDescendants()
local liftspeed = 8 -- The lift speed. Do not set to negative.
local dbtime = 2 -- How long you want the elevator to stay idle before it can receive its next order.
local isMoving = script.Parent.IsMoving
reservedstations = {}
sta = script.Parent.Stations:GetChildren()
currentstation = 1
selectedstation = 2
debounce = false
local function anchor(boolarg)
for _, parts in pairs(liftParts) do
if parts:IsA("BasePart") then
parts.Anchored = boolarg
end
end
end
function descend()
print("Entering descend")
isMoving.Value = true
repeat wait() until doorvalue.Value == false
print("ln24 Executed; descend")
wait(1)
anchor(false)
bodyvelocity.velocity = Vector3.new(0,-liftspeed,0)
print("ln27 executed; descend")
repeat wait(0.001) until currheight.Position.Y <= sta[selectedstation].Position.Y
print("ln29 Executed; descend")
bodyvelocity.velocity = Vector3.new(0,0,0)
wait(2)
isMoving.Value = false
currentstation = selectedstation
anchor(true)
wait(dbtime)
debounce = false
print("Leaving descend")
end
function ascend()
print("Entering ascend")
wait(3)
isMoving.Value = true
repeat wait() until doorvalue == false
wait(1)
anchor(false)
bodyvelocity.velocity = Vector3.new(0,liftspeed,0)
repeat wait(0.001) until currheight.Position.Y >= sta[selectedstation].Position.Y
bodyvelocity.velocity = Vector3.new(0,0,0)
wait(2)
isMoving.Value = false
currentstation = selectedstation
anchor(true)
wait(dbtime)
debounce = false
print("Leaving ascend")
end
function move()
if sta[selectedstation].Position.Y < sta[currentstation].Position.Y and debounce == false then
debounce = true
descend()
elseif sta[selectedstation].Position.Y > sta[currentstation].Position.Y and debounce == false then
debounce = true
ascend()
end
end
function Stationone()
if debounce == false then
selectedstation = 1
wait(1)
move()
end
end
function Stationtwo()
if debounce == false then
selectedstation = 2
wait(1)
move()
end
end
script.Parent.LiftCar.LiftControl.Buttons.StationACall.ClickDetector.MouseClick:Connect(Stationone)
script.Parent.LiftCar.LiftControl.Buttons.StationBCall.ClickDetector.MouseClick:Connect(Stationtwo)
Here is the script that welds the car together (I didn’t write this part, so I don’t know how he did the C1 and C0 here)
function Weld(x, y)
if x:IsA("BasePart") and y:IsA("BasePart") then
local weld = Instance.new("Weld")
weld.Part0 = x
weld.Part1 = y
weld.C0 = x.CFrame:inverse() * CFrame.new(x.Position)
weld.C1 = y.CFrame:inverse() * CFrame.new(x.Position)
weld.Parent = x
end
end
local prev
local unanchor = {}
function search(n)
for i, v in pairs(n:getDescendants()) do
if v:IsA("BasePart") then
if prev then
Weld(v, prev)
prev = v
unanchor[#unanchor + 1] = v
else
prev = v
unanchor[#unanchor + 1] = v
end
end
search(v)
end
end
function searchgate()
local models = script.Parent:GetChildren()
for _, mods in pairs(models) do
if mods:IsA("Model") and mods.Name ~= "Doors" then
print("Mods =", mods.Name)
search(mods)
end
end
end
searchgate()
And here is the script that actually gets the door to open/close when IsMoving is false/true. This is also the script that creates and destroys the welds in the doors.
script.Parent.LeftDoor.PrimaryPart = script.Parent.LeftDoor.Ppart
script.Parent.RightDoor.PrimaryPart = script.Parent.RightDoor.Ppart
b1l = script.Parent.LeftDoor.PrimaryPart.CFrame
b2l = script.Parent.RightDoor.PrimaryPart.CFrame
l = 30 --time it takes to fully open the door (1 second divided by 30)
db = false
tim = 0
local function close()
print("Door closing")
if db == false then
db = true
script.Parent.LeftDoor.Ppart.Sound:Play()
script.Parent.RightDoor.Ppart.Sound:Play()
for i = 1, l do
script.Parent.LeftDoor:SetPrimaryPartCFrame(b1l * CFrame.new(-script.Parent.LeftDoor.PrimaryPart.Size.X/l*i, 0, 0))
script.Parent.RightDoor:SetPrimaryPartCFrame(b2l * CFrame.new(-script.Parent.RightDoor.PrimaryPart.Size.X/l*i, 0, 0))
wait()
end
wait(1)
db = false
end
end
local function open()
print("Door opening")
if db == false then
db = true
script.Parent.LeftDoor.Ppart.Sound:Play()
script.Parent.RightDoor.Ppart.Sound:Play()
for i = 1, l do
script.Parent.LeftDoor:SetPrimaryPartCFrame(b1l * CFrame.new(-script.Parent.LeftDoor.PrimaryPart.Size.X/l*(l-i), 0, 0))
script.Parent.RightDoor:SetPrimaryPartCFrame(b2l * CFrame.new(-script.Parent.RightDoor.PrimaryPart.Size.X/l*(l-i), 0, 0))
wait()
end
wait(1)
db = false
end
end
local doorOpen = script.Parent.Parent.Parent.Dooropen
IsMoving.Changed:Connect(function()
weldermain()
print("IsMoving triggered. IsMoving val =", IsMoving.Value)
if IsMoving.Value == false then
open()
wait(3)
doorOpen.Value = true
else
print("IsMoving val=", IsMoving.Value)
close()
wait(3)
doorOpen.Value = false
print("Dooropen value is", doorOpen.Value)
end
end)
Does anyone know how to get my parts to remain in position during the descent? I also need to know why my elevator is doing a free fall instead of going to where it needs to be.
Thank you for the help.