Elevator randomizer script not working

Hey, im currently trying to make one of those random elevator systems, i made a script but when i tried it , the random places werent being teleported infront of the elevator, here is the script:

local door = game.Workspace.door
local pl = game.Workspace.plates

local blue = pl.blue.blue
local brown = pl.b.brown
local red = pl.red.red
local g = pl.g.green




while true do
	wait(2.5)
	door.Transparency = 1
	door.CanCollide = false
	wait(2.5)
	door.Transparency = 0
	door.CanCollide = false
end

while true do
	local randomplate = math.random(1, 4)
	local newPosition = Vector3.new(50.031, 41.296, -2.112) 

	if randomplate == 1 then
		blue.Position = newPosition
		blue.Parent.Position = newPosition
	elseif randomplate == 2 then
		g.Position = newPosition
		g.Parent.Position = newPosition
	elseif randomplate == 3 then
		red.Position = newPosition
		red.Parent.Position = newPosition
	elseif randomplate == 4 then
		brown.Position = newPosition
		brown.Parent.Position = newPosition
	end
	wait(5)
	brown.Position = Vector3.new(50.93, 0.5, -67.946)
	red.Position = Vector3.new(50.93, 0.5, -67.946)
	g.Position = Vector3.new(50.93, 0.5, -67.946)
	blue.Position = Vector3.new(50.93, 0.5, -67.946)
	
	brown.Parent.Position = Vector3.new(50.93, 0.5, -67.946)
	red.Parent.Position = Vector3.new(50.93, 0.5, -67.946)
	g.Parent.Position = Vector3.new(50.93, 0.5, -67.946)
	blue.Parent.Position = Vector3.new(50.93, 0.5, -67.946)
end
2 Likes

While I can’t offer much to help you, I can request one thing for code readability and efficiency. Gather your floors in a table with :GetChildren() and use a math.random(1,#table) to get a random floor.

local floors = game.ServerStorage.Floors:GetChildren()

while true do 
      wait(3)
      local choice = floors[math.random(1,#floors)]
      choice.Parent = workspace
      wait(3)
      choice.Parent = game.ServerStorage.Floors
end
2 Likes