Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[ SOLVED BY MYSELF ] Why when generating my rooms, some are delayed in Y axis and some not?

local ReplicaredStorage = game:GetService("ReplicatedStorage")
local RoomsFolder = ReplicaredStorage:WaitForChild("Rooms")
local Rooms = RoomsFolder:GetChildren()

local MaxRooms = 50
local RoomsLoaded = 0

--Loading all rooms
repeat wait(0.2)
	local SelectedRoom = Rooms[math.random(1, #Rooms)]
	local ClonedSelectedRoom = SelectedRoom:Clone()
	RoomsLoaded = RoomsLoaded + 1
	ClonedSelectedRoom.Parent = game.Workspace
	ClonedSelectedRoom.Name = "Room"..RoomsLoaded
	local PreviousPart = game.Workspace:FindFirstChild("Room"..RoomsLoaded - 1)
	local MAIN = PreviousPart:FindFirstChild("MAIN")
	local TELEPORT = PreviousPart:FindFirstChild("TELEPORT")
	local NewPos = Vector3.new(MAIN.Size.X, 0, 0) + TELEPORT.Position
	ClonedSelectedRoom:MoveTo(NewPos)
until RoomsLoaded == MaxRooms

--Loading the end room
local SelectedRoom = ReplicaredStorage:WaitForChild("RoomEnd")
local ClonedSelectedRoom = SelectedRoom:Clone()
ClonedSelectedRoom.Parent = game.Workspace
ClonedSelectedRoom.Name = "RoomEnd"
local PreviousPart = game.Workspace:FindFirstChild("Room"..MaxRooms)
local MAIN = PreviousPart:FindFirstChild("MAIN")
local TELEPORT = PreviousPart:FindFirstChild("TELEPORT")
local NewPos = Vector3.new(MAIN.Size.X, 0, 0) + TELEPORT.Position
ClonedSelectedRoom:MoveTo(NewPos)

There's no error ofc, Some rooms are delayed of 1.5 studs in the Y axis for no reason, NewPos is supposed to be always the same, the "TELEPORT" parts are all the same size are perfectly centered but it still can be a problem with that (TELEPORT parts are like the end of the room and MAIN parts are the start of the room and also the primary part of that room. (because the room is a model.)), please help, thanks.

1 answer

I solved my own problem, it was just some math issues, i added a "if then" to check if the room is not in the same Y axis than the previous room so it fixes the room's position.

This discussion is preserved as it was. New answers, comments, and votes are closed.