Ability to ensure a server function runs before clients connect

As a Roblox developer, it is currently too difficult to ensure a function will run before clients connect to the server.

Context:

When a server starts in my game, a model is cloned x8, repositioned, then its parts modified. This results in about 4k unreplicated one-time server-sided modifications, easily within the capabilities of a Roblox server.

Recently, I’ve added a datastore yield before this executes. This sometimes gives the first client enough time to load into game, thus processing 4k replications. This really becomes an issue while using StreamingEnabled, as for technical reasons some of these parts are persistent.

The issue:

Running modifications on persistent parts is known to be expensive, but only when a client exists to replicate to. In my case, this actually ends with my script timing out mid way and shutting down entirely, preventing my game from loading. When the server finishes the operations before the client loads, there are never issues.

The solution:

The ability to ensure a function runs before clients connect would be beneficial to my use case as I would be able to easily avoid needless replications the client doesn’t need to see. Having this issue addressed would also help other use cases aside from my own. For example, sometimes a client will connect to the server before Players.PlayerAdded has a chance to connect. This would allow us to connect necessary functions before clients join with ease.

game:Await(function()
    
    scaryPartOperations()
    
    game:GetService("Players").PlayerAdded:Connect(function(player)
        -- Alwyas detects first client!
    end)
    
    -- Clients unable to join until this returns
    return
end)
13 Likes

I like the Idea It would enable us much more control on Initialisation of our games :+1: :heart:

1 Like

Good idea, but its not really practical unless you have this specific use case.

Also, this is already possible by handling character loading yourself, via disabling Players.CharacterAutoLoads and calling Player:LoadCharacter(), among other stuff you could implement.

LoadCharacter() is not related to what is discussed above. I’m pretty sure Roblox doesn’t wait until your character is loaded to replicated objects from the server

This seems very niche and I don’t even think this API could work (What happens if a script tries to bind a callback after a client has joined?)

Is there a reason you can’t just do your scary part operations in an unreplicated container and then mass reparent them when finished? They’ll have to be replicated at some point, anyway.