Hello! I am currently working on a elevator and am running into an issue in terms of how I would go about making it move.
Bascially, the elevator is already done and put together, but my problem is for it to actually make it move. I avoided using TweenService since from what I’ve heard, it’s not ideal for moving a elevator, but I can’t seem to find another way to be able to make it move.
I know I can use AlignPosition, but my problem is that this elevator has doors in it that are tweened whenever the elevator arrives to the next floor. And in order for me to use AlignPosition, I would need to weld all the parts of the elevator to the main part that will be moved so they all move along with it, and that includes the doors, which if I weld the doors to the main part, it won’t be able to be tweened anymore and just simply stay in place, which is my problem. It’s a bit hard to explain but that’s the best way I can put it.
Simply, how can I move this elevator while also still being able to make the doors be tweened?
You could try making an illusion of it moving by just shutting the doors, playing sounds, maybe a very, VERY slight camera shake, and just teleporting the player. This only works if you cant see the elevator from the outside, and theres no windows in the elevator
You can use the physics constraint method and use a Motor6D on the doors, with Motor6D you can use C0(or C1, I haven’t used it for some time) and simply tween the value, the door will move while also moving with the elevator
By physics constraint method you mean to just use AlignPosition right?
My problem with that is if I did use AlignPosition for this elevator, the main part that’s getting moved will have to be unanchored, meaning that when I run the game, it’s just gonna fall down. So I’m not sure if I can do that? I’m somewhat new to AlignPosition still so I don’t know everything about it, but I do know that you can’t use it with anchored parts, so I’m not sure how I would keep the elevator from falling if I did use it.
The way I was thinking of is to just stick with tweens since I find relying on physics quite troublesome… so that’s exactly what I did.
The way this works is that the elevator model is welded when moving, then unwelded and anchored to allow the door tweens to play.
If you want to see the code for yourself, here it is:
Summary
local Elevator = {}
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
2, -- assuming it goes back & forth between just 2 floors. If you have more, it'd be wise to use t=d/s formula
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut
)
local elevator = workspace.Elevator
local anchor = elevator.PrimaryPart
function Elevator.weld(model: Model)
for _, obj in model:GetDescendants() do
if obj == anchor then continue end
if not obj:IsA("BasePart") then continue end
local weld = Instance.new("WeldConstraint")
weld.Part0 = obj
weld.Part1 = anchor
weld.Parent = anchor
obj.Anchored = false
end
end
function Elevator.unweld(model: Model)
for _, obj in model:GetDescendants() do
if obj:IsA("WeldConstraint") then
obj:Destroy()
elseif obj:IsA("BasePart") then
obj.Anchored = true
end
end
end
function Elevator.openAndCloseDoors()
Elevator.unweld(elevator)
local leftDoor = elevator.Doors.Left
local rightDoor = elevator.Doors.Right
--// open doors
tweenService:Create(rightDoor, tweenInfo, {CFrame = rightDoor.CFrame + Vector3.new(0, 0, 4)}):Play()
local leftTween = tweenService:Create(leftDoor, tweenInfo, {CFrame = leftDoor.CFrame - Vector3.new(0, 0, 4)})
leftTween:Play()
leftTween.Completed:Wait()
--// close doors
tweenService:Create(rightDoor, tweenInfo, {CFrame = rightDoor.CFrame - Vector3.new(0, 0, 4)}):Play()
local leftTween = tweenService:Create(leftDoor, tweenInfo, {CFrame = leftDoor.CFrame + Vector3.new(0, 0, 4)})
leftTween:Play()
leftTween.Completed:Wait()
--// go down
Elevator.weld(elevator)
end
function Elevator.down()
local tween = tweenService:Create(anchor, tweenInfo, {CFrame = workspace.BottomPos.CFrame})
tween.Completed:Connect(function()
Elevator.openAndCloseDoors()
Elevator.up()
end)
tween:Play()
end
function Elevator.up()
local tween = tweenService:Create(anchor, tweenInfo, {CFrame = workspace.TopPos.CFrame})
tween.Completed:Connect(function()
Elevator.openAndCloseDoors()
Elevator.down()
end)
tween:Play()
end
function Elevator.start()
task.wait(3)
-- start the loop (for demonstration purposes)
Elevator.weld(elevator)
Elevator.up()
end
return Elevator
I’ve been told that my approach is garbage. I’m going to have to agree. I’ve tried Prismatic Constraints in the past, and it seemed to work out way better. I’m not an all pro at it by far, but I’m sure I saved a tutorial that looked promising. Sure looks smooth anyways.. Found it and set a link.
Not only that, you can also use Prismatic Constraint as well which, in the docs page I just linked, is mentioned to be good for stuff that requires sliding, like sliding doors and elevators.
This method seems the best for me honestly, since I’m not the greatest at physics on roblox its the easiest to do so I chose to do this one. I already made the elevator with the method and it works good now! Thank you for the help, and I appreciate others for helping also.