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)