Do server-side scripts run before the entire game has loaded for the server?

I recently noticed a discussion where people were discussing when :WaitForChild() is necessary and when it is not. I think that a lot of Roblox’s loading procedures remain a mystery to a lot of us, which leads to overusing :WaitForChild() just to be safe.

So, my question here is: can we expect the entire environment to exist prior to the execution of server scripts in ServerScriptService?

4 Likes

Yes.

7 Likes

You basically never have to use :WaitForChild() on the server for instances that are pre-made in studio. The only time you’d need to use :WaitForChild() on the server is if you are creating instances via code, and are needing a reference to it in an alternate script.

Always use :WaitForChild() on the client as it takes time to replicate.

10 Likes

While we’re here, I also heard something about client replication that perhaps you can shed some light on.

I heard that, when a top level object (let’s say PlayerGui.ScreenGui) is replicated, all of its’ children will exist immediately. Which would mean that we wouldn’t have to be using :WaitForChild() on children of that ScreenGui object, if my explanation makes sense. Is that true?

really just trying to reduce my usage of :WaitForChild() as it’s really ugly and bad if it’s unnecessary

2 Likes

No, you’ll have to WaitForChild for each child, but that’s just a quirk of GUI objects. For everything else, only the parent.

Also, if an object is one that exists in Studio (i.e. it’s premade), you don’t need to WaitForChild on it unless its a StarterGui object.

2 Likes

No, you cannot.

I’ve tested with the .ChildAdded event, and it seems like scripts insife ServerScriptService are ran before most of the Workspace children are loaded in.

Direct indexing is discouraged, therefore.

1 Like

Does anyone else have any info on this?

Reviving thread again, I don’t get why we can’t get a straight answer on this. This is pretty important to not breaking core server scripts by accidentally indexing into something before it exists, and halting the thread from the error