How do I fix this escalator?

Hello! I tried to make an escalator. Since I made it go up, my only issue is how do I make it go down.

Script inside up escalator:

local steps = script.Parent:WaitForChild("Steps"):GetChildren()

table.sort(steps, function(a, b)
	return a.Position.Y < b.Position.Y
end)

local startPos = steps[1].Position
local endPos = startPos.Y + (#steps - 1) * steps[1].Size.Y

local speed = 1

local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

while wait(speed) do
	
	for _, step in pairs(steps) do
		
		if step:IsA("Part") then
			local y, z = (1/speed) * step.Size.Y, (1/speed) * step.Size.Z
		
			step.Velocity = Vector3.new(0, y, z)
			
			if math.floor(step.Position.Y + 0.5) >= math.floor(endPos) then
				step.Position = startPos
			end
			
			local tween = tweenService:Create(step, info, {Position = step.Position + Vector3.new(0, step.Size.Y, step.Size.Z)})
			
			tween:Play()
		end
		
	end
	
end

Script inside down escalator:

local steps = script.Parent:WaitForChild("Steps"):GetChildren()

table.sort(steps, function(a, b)
	return a.Position.Y > b.Position.Y
end)

local startPos = steps[1].Position
local endPos = startPos.Y + (#steps - 1) * steps[1].Size.Y

local speed = 1

local tweenService = game:GetService("TweenService")
local info = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

while wait(speed) do

	for _, step in pairs(steps) do

		if step:IsA("Part") then
			local y, z = (1/speed) * step.Size.Y, (1/speed) * step.Size.Z

			step.Velocity = Vector3.new(0, y, z)

			if math.floor(step.Position.Y + 0.5) >= math.floor(endPos) then
				step.Position = startPos
			end

			local tween = tweenService:Create(step, info, {Position = step.Position - Vector3.new(0, step.Size.Y, step.Size.Z)})

			tween:Play()
		end

	end

end

NOTE: Each escalator includes 11 steps. Here’s the video I watched:

try just setting speed to -1

might work i mean

Sadly it didn’t work. Sorry. (Char limit)

Inside of step.Velocity = Vector3.new(0, y, z) instead of trying to change the speed variable to a negative, you could try multiplying the y, z variables by -1, to give them negative values and hopefully reversing the direction.

Do you mean like this:

step.Velocity = Vector3.new(0, y * -1, z * -1)

Because nothing changed. Also, when I have Position = step.Position - Vector3.new(0, step.Size.Y, step.Size.Z) in the tweenService:Create() line without it, this strange thing happens:

I dont see any problems here (except the fact that the blocks arn’t getting teleported back to the top), you just have to change this line:
if math.floor(step.Position.Y + 0.5) >= math.floor(endPos) then
step.Position = startPos
end
so it instead check if the block is at the bottom rather then the top, and put it to the top instead of bottom (im pretty sure just doing sometime like switching the startPos and endPos variables around would work)

1 Like