Avoiid room colision

helllo. i have left rooms, right rooms and straight rooms. the problem is that they often collide like this.


my script looks like this…

function Create_Room()

	if #script.ENEMY_FOLDER.Value:GetChildren() == 0 then
		if db then db = false
			if script.ROOM_AMOUNT.Value == math.floor(script.MAX_ROOMS.Value/2 + 0.5) and script.CAN_CREATE_LIBARY.Value == true then
				script.CAN_CREATE_LIBARY.Value = false
				Seek_Eyes()
				task.wait()
				LIBARY()

			elseif script.ROOM_AMOUNT.Value < script.MAX_ROOMS.Value then

				local SELECTED_FOLDER = false

				if script.ROOM_AMOUNT.Value > math.floor(script.MAX_ROOMS.Value/2 + 0.5) then

					SELECTED_FOLDER = script.Rooms_Folder.Value.GREENHOUSE_ROOMS

				elseif script.ROOM_AMOUNT.Value < math.floor(script.MAX_ROOMS.Value/2 + 0.5) then

					SELECTED_FOLDER = script.Rooms_Folder.Value.NORMAL

				end

				task.wait(0.2)

				script.ROOM_AMOUNT.Value = script.ROOM_AMOUNT.Value + 1


				local Rooms = SELECTED_FOLDER:GetChildren()
				local Room = Rooms[math.random(1, #Rooms)]
				if Room ~= nil then
					warn(Room.Name)
					local New_Room = Room:Clone()
					New_Room.Parent = script.ACTIVE_ROOMS_FOLDER.Value
					New_Room.Name = script.ROOM_AMOUNT.Value
					script.Trigger.Value = New_Room:FindFirstChild("END")
					task.wait()
					New_Room:PivotTo(script.Current_Room.Value:WaitForChild("END").CFrame)
					task.wait()
					script.Current_Room.Value = New_Room


					AddFurniture()
					warn("created room")

					if script.ROOM_AMOUNT.Value > 3 then
						local Chance = math.random(1,6)
						warn(Chance)
						if Chance == 1 then
							--Rush()
						elseif Chance == 2 then
							--Ambush()
							script.SOUNDS.Dark_Room:Play()
						else
						end
					end
				end


				script.Cleaning.CYCLE.Value = script.Cleaning.CYCLE.Value + 1
				if script.Cleaning.CYCLE.Value == script.Cleaning.MAX_CYCLE.Value then
					Clear_Old_Rooms()
					script.Cleaning.CYCLE.Value = 0
				end

			elseif script.ROOM_AMOUNT.Value == script.MAX_ROOMS.Value and script.CAN_CREATE_END.Value == true then
				MakeLastRoom()
				task.wait()
				db = true
			elseif script.CAN_CREATE_END.Value == false then
				script.SPAWN_ROOM.Value:FindFirstChild("END").CanTouch = false
				task.wait()
				Create_Room()
				script.SPAWN_ROOM.Value:FindFirstChild("END").CanTouch = true
				db = true
			end
		end
		task.wait(0.2)
		db = true
	end
end

i would highly appreciate if someone could implement a detection for when already left or right room sapwned to evoid colision

Please read this page thoroughly and change your topic accordingly. We in the Dev forum would love to help, but help us help you by following the guidelines of this post. Thank you! :smile:

I would say store the last room direction and make sure that room your generating doesn’t go in the same direction as the last room. This can be done pretty easily by just adding a String value in the room model and making the value “L”, “R”, or, “S”, storing it in a table when you generate a room, and then when you next randomly pick a room, check to see if it’s the same, if it’s not, pick another random room. After that just make sure you clear the table after you’ve done picking a room.

this would enllarge the time i need to pick a room right?

I mean yeah, but barely - miliseconds