Game loads weird, possibly load order. Any tips?

So i got the bright idea to turn all my base scripts to packages. I did it and now i’m here.
50/50 chance of it all working correctly in the client (in studio it works 90% and my base scripts are fine). Also terrain does this:


Based on this, and the fact that the following things are messed up: terrain, physics, ect… i’ve concluded that maybe it tries to load my scripts before or while loading main things. Loading order is messed up basically.

Structure:
image
ServerScriptService:
EssentialsLoader is… the loader (potential problem source)
ServerStorage:
SummitEssentials are my aforementioned base scripts
PlaceSpecific if things need to be overwritten like ui elements being enabled/disabled

The loader just compares the contents of the PlaceSpecific and SummitEssentials folders and inserts it to their places.

What’s inside the SummitEssentials:
image

Loader script: (don’t mine it being leaked cuz… it just compares 2 folders :man_shrugging:)

essentials = game.ServerStorage.SummitEssentials
placeSpecific = game.ServerStorage:FindFirstChild("PlaceSpecific")

if placeSpecific ~= nil then
	local placeSpecificChildren = placeSpecific:GetChildren()
	for i = 1, #placeSpecificChildren, 1 do
		local folderToCheck = essentials:FindFirstChild(placeSpecificChildren[i].Name)
		if folderToCheck == nil then
			placeSpecificChildren[i].Parent = essentials
		else
			local placeSpecificFolderChildren = placeSpecificChildren[i]:GetChildren()
			for j = 1, #placeSpecificFolderChildren, 1 do
				if folderToCheck:FindFirstChild(placeSpecificFolderChildren[j].Name) ~= nil then
					folderToCheck[placeSpecificFolderChildren[j].Name]:Destroy()
				end
				placeSpecificFolderChildren[j].Parent = folderToCheck
			end
		end
	end
	placeSpecific:Destroy()
end

specialFolders = {essentials.StarterPlayerScripts, essentials.StarterCharacterScripts}

for i = 1, 2, 1 do
	local tempChildren = specialFolders[i]:GetChildren()
	local to = game.StarterPlayer:FindFirstChild(specialFolders[i].Name)
	for j = 1, #tempChildren, 1 do
		tempChildren[j].Parent = to
	end
	specialFolders[i]:Destroy()
end

essentialsChildren = essentials:GetChildren()

for i = 1, #essentialsChildren, 1 do
	local tempChildren = essentialsChildren[i]:GetChildren()
	local to = game:FindFirstChild(essentialsChildren[i].Name)
	for j = 1, #tempChildren, 1 do
		tempChildren[j].Parent = to
	end
end

essentials:Destroy()

game.StarterPlayer.StarterPlayerScripts:FindFirstChild("PlayerModule"):Destroy()
game.StarterPlayer.StarterPlayerScripts:FindFirstChild("RbxCharacterSounds"):Destroy()
game.StarterPlayer.StarterPlayerScripts:FindFirstChild("PlayerScriptsLoader"):Destroy()

script:Destroy()

So the questions lined up:
Is the load order really what’s wrong?
Can i somehow fix it?
Can i load my scripts before the game loads?
Am i even on the right track?

Any help is appreciated.

What happens if you take the EssentialsLoader script and make it make it inactive to see if it is what’s lagging the load?

Well if i disable the loader it just…


But if you ment to start the game without my scripts, then it works just like any other baseplate/terrain demo.

Create an array containing the names of services you’d like to fill in chronological order.

local packageOrder = { -- this controls the order in which packages are loaded in
	"ServerStorage",
	"Workspace",
	"ReplicatedFirst",
	"ReplicatedStorage",
	"ServerScriptService",
	-- un-included services will be loaded afterwards, in random order	
}

Iterate over that array and transfer the children to the service by matching name.

for _,directoryName in next,packageOrder do
    -- transfer children from the package to the service matching the directoryName
end
2 Likes

This might just work.
Well it’s certainly cleaner than my bowl of sphagetti i threw together just to finish this long project.
I’ll report later. (i really need to learn theese Next and InPairs things don’t i?)

So… the following happened:


Hey at least base roblox things work now.

And then some editing, fitting and a plate of schnitzel later:

Sometimes you spend so much time on something that your brain goes numb. Anyone reading this down the line: TAKE A BREAK

Thank you @Soybeen . Marked as solution and thank you for your time.

1 Like

I struggle to imagine a problem that could not be solved by a plate of schnitzel :smile:

2 Likes