Making An Elevator

okay so, as you can see here i am making an elevator for a hotel in my game by breaking apart code from other models, and while i don’t exactly understand what’s going on, i do have a general knowing of what to change / how to make my own model around the code to get it to work. well i guess there are things called BoolValues too?? this model to the left is (not mine) way more advance and uses a lot of coding i don’t quite understand yet, however i want to take it apart and use it to my elevator so i can have “led buttons” a ding, doors opening and so on. i’m slowly learning more and more about this stuff- keep in mind i “started coding” 3 days ago. and by “coding” i just mean trying to get a grasp on anything-

this is just really confusing at times but i’m not giving up until i’m able to rework my elevator to work like the one to the left >:D

if anyone has any videos on this stuff that would be amazing- i’ll link the model to the elevator here incase i didn’t explain something correctly (which i know i haven’t) in case people have any pointers to help me learn this stuff better! or just roblox pages i should be going/looking to!!!

https://create.roblox.com/store/asset/13309856762/Elevator

1 Like

There’s practically 2 ways to make an elevator: Using physics or TweenService. I don’t know what the model you’re looking at uses but I prefer tweening and it looks like tweening is the better option in your scenario.

This introduces us to tweening models, which opens up a lot of doors. I’ll mostly just be explaining the general concept, I’ll show a solution I made recently at the bottom of this post.

Tweening Models

A model must first have a PrimaryPart, which is a property you can set as a BasePart. You should ideally have this part perfectly in the middle of the model to make the movement accurate (and also better to have it invisible)..

After making the PrimaryPart, you must weld all of the BaseParts in the model to the PrimaryPart. This will keep the whole model intact when unanchored.

The PrimaryPart of the model should be anchored, and everything else unanchored. The welds hold everything in place.

Now that everything is prepared, we can simply tween the PrimaryPart and the whole model will move along with it as if it were one. This gives the illusion of tweening models when in reality you’re still tweening one part and the welds just hold the model together.

Applying this to an elevator

Now we can tween the elevator up and down. But the thing with tweens is that you can’t really tween an object that’s moving. This makes the problem with tweening the doors open/close hard.

The solution I proposed in the post below is to delete all of the welds in the elevator once the elevator has reached its floor and the tween finishes and anchor the whole thing. And then tween the doors separately (you might need to weld the doors too if they’re a model/have multiple parts).

After the doors close and the elevator is ready to move, just weld the elevator back up and unanchor everything but the PrimaryPart, then the elevator is ready to be tweened again.

More advanced things

If your elevator has functioning buttons and goes between more than 2 floors, then that’s where things get a bit tricky. If you’d like me to help with this though I’ll go for it and tell you how I did it.

Also, if you want your elevator to be realistic and add button press queueing and floor prioritization depending on whether it’s moving up or down and a selected floor is on the way, then uhh :skull: (i could still try)

The post in question: Problem with making my elevator move [SOLVED]

4 Likes
X = false

MovingPart = script.Parent.MovingPart

local TweenService = game:GetService("TweenService")

Length = 10
Studs = 17.55

local tweenInfo = TweenInfo.new(Length,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut,0,false,0)

local up = {CFrame = MovingPart.CFrame + MovingPart.CFrame.UpVector * Studs}
local down = {CFrame = MovingPart.CFrame }

local CUp = TweenService:Create(MovingPart,tweenInfo,up)
local CDown = TweenService:Create(MovingPart,tweenInfo,down)

script.Parent.ElevatorButton.ClickDetector.MouseClick:Connect(function()
	if State == "Down" and X == false then
		X = true
		MovingPart.Sound:Play()
		CUp:Play()
		wait(Length)
		State = "Up"
		MovingPart.Sound:Stop()
		X = false
	elseif State == "Up" and X == false then
		X = true
		MovingPart.Sound:Play()
		CDown:Play()
		wait(Length)
		State = "Down"
		MovingPart.Sound:Stop()
		X = false
	end
end)

script.Parent.DownCallButton.ClickDetector.MouseClick:Connect(function()
	if State == "Up" and X == false then
		X = true
		MovingPart.Sound:Play()
		CDown:Play()
		wait(Length)
		State = "Down"
		MovingPart.Sound:Stop()
		X = false
	end
end)

script.Parent.UpCallButton.ClickDetector.MouseClick:Connect(function()
	if State == "Down" and X == false then
		X = true
		MovingPart.Sound:Play()
		CUp:Play()
		wait(Length)
		State = "Up"
		MovingPart.Sound:Stop()
		X = false
	end
end) 

so you can see behind the code and visuals of what i currently have!
the model i took the script/reworked it into mine from - https://create.roblox.com/store/asset/6308784398/Maintenance-Elevator

i just wanted to know like how to understand this a bit better like coding wise, videos are very much appreciated going into more explanation, while i do use the Roblox pages of what things mean “Enum” is still confusing of what that exactly means, and maybe just like how “defining code” works? like how they use

local CUp = TweenService:Create(MovingPart,tweenInfo,up)
local CDown = TweenService:Create(MovingPart,tweenInfo,down)

and then refer to it later? it would be nice to understand those more- i think i will be able to break it down for the model above (actual post with the moving doors, buttons, LEDs, sounds and like all the shabang) but like, i just want to understand it better?

2 Likes