[SOLVED] Is this a good way to make an elevator?

I made this elevator with a RodConstraint, It works fine but it’s a little jerky and unstable, Any suggestions?

Script:

local Rods = script.Parent.Parent.Connection2.Rod1


function ButtonClicked1(Player)
	script.Parent.Close.Transparency = 0
	script.Parent.Close.CanCollide = true
	script.Parent.Parent.Close2.Transparency = 0
	script.Parent.Parent.Close2.CanCollide = true
	script.Parent.Parent.Close3.Transparency = 0
	script.Parent.Parent.Close3.CanCollide = true
				script.Parent.Parent.Close4.Transparency = 0
	script.Parent.Parent.Close4.CanCollide = true
	script.Parent.Sounds.Move:Play()
	print("Whirr.")
	wait(1)
	Rods.Length = 29
	wait(.1)
	Rods.Length = 28
    wait(.1)
	Rods.Length = 27
	wait(.1)
	Rods.Length = 26
    wait(.1)
	Rods.Length = 25
	wait(.1)
	Rods.Length = 24
	wait(.1)
	Rods.Length = 23
	wait(.1)
	Rods.Length = 22
	wait(.1)
	Rods.Length = 21
	wait(.1)
	Rods.Length = 20
	wait(.1)
	Rods.Length = 19
	wait(.1)
	Rods.Length = 18
	wait(.1)
	Rods.Length = 17
	wait(.1)
	Rods.Length = 16
	wait(.1)
	Rods.Length = 15
	wait(.1)
	Rods.Length = 14
	wait(.1)
	Rods.Length = 13
	wait(.1)
	Rods.Length = 12
	wait(.1)
	Rods.Length = 11
	wait(.1)
	Rods.Length = 10
	wait(.1)
	Rods.Length = 9
	wait(.1)
	Rods.Length = 8
	wait(.1)
	Rods.Length = 7
	wait(.1)
	Rods.Length = 6
	wait(.1)
	Rods.Length = 5
	wait(.1)
    Rods.Length = 4
    wait(.1)
	Rods.Length = 3
	wait(.1)
	Rods.Length = 2
	wait(.1)
	Rods.Length = 1
	wait(1)
	print("Ding!")
	script.Parent.Sounds.Ding:Play()
	script.Parent.Sounds.Move:Stop()
		script.Parent.Close.Transparency = 1
	script.Parent.Close.CanCollide = false
			script.Parent.Parent.Close3.Transparency = 1
	script.Parent.Parent.Close3.CanCollide = false
	script.Parent.Parent.Close2.Transparency = 0
	script.Parent.Parent.Close2.CanCollide = true
end
1 Like

Certainly, you could instead use a numeric for loop for the rods’ length.

for i = 29, 1, -1 do
	wait(.1)
	Rods.Length = i
end

– Edited: Overlooked the .1, mistook it for 1.

1 Like

You should use TweenService instead of setting the length in increments. Since you’re not having the length be set to any values between each integer, this will make its shrinking look jerky.

local tweenService = game:GetService("TweenService")

local tween = tweenService:Create(Rods, TweenInfo.new(2.90, Enum.EasingStyle.Linear), {Length = 1})

tween:Play() -- this causes the rod to shrink over a period of 2.9 seconds but doesn't wait that time
tween.Completed:Wait() -- this will cause the wait for 2.9 seconds
wait(1)
print("Ding")

Comparison:
Tween (left) vs numeric loop (right)

16 Likes
1 Like

Thanks! Works perfectly and looks good!

1 Like

Just another suggestion: Make variables for your parts. You’ll find it much easier while you’re coding.

2 Likes