Use packages for each service (ServerStorage,etc) without messing up hierarchy?

My game needs to be a multiplace game, therefore I thought of using packages to keep scripts synced up between the places. However, it tends to mess up the hierarchy of all the scripts already calling the services!

How would I get around this, or act like the package folder does not exist?

2 Likes

Can’t really understand what is the problem. Is it that packages are running before the other scripts?

Nope! For example, if everything in ServerScriptService is in a package, then I’d have to start calling

game:GetService("ServerScriptService").Package

Instead of it without the package. That’s what I meant by messing up hierarchy.

Have you tried to move to ServerScriptsService using script.Parent = script.Parent.Parent for each script? Seems like the easiest solution.

yeah I was thinking of that, don’t know why but I felt it might cause some problems. Looks like the only solution though, so I’ll probably just do that for the time being.

wait, what about things that arent scripts?

Use one of already existing scripts to create a seperate script that will move those objects too.

Also, don’t forget, it may take a little bit for those scripts to move, so it’s much safer to access them using :WaitForChild("scriptname")

what about a script that loops through the whole game and if something is named “Package” it would transport all the children inside it outside of the folder? or would that be too unoptimized?

for example:

for _,pack in pairs(game:GetDescendants()) do
	if pack.Name == "Package" then
		for _,v in pairs(pack:GetChildren()) do
			v.Parent = v.Parent.Parent
		end
	end
end

Sure, you can try that.
Using game:GetDescendants() may be sometimes heavy, if you have like 1k objects in game.
If you’ll use this way, make sure every unpacked object you are trying to get is accessed using :WaitForChild("object").

where in the code given would I use :WaitForChild() though?

If you want to access any unpacked object from your package, use WaitForChild.
Because the objects aren’t instantly moved from it you’ll need to wait for them.