I have been searching the forums for this answer, but all seem to talk only about checking on the server, or loading assets at a loading screen.
However, my situation requires that the server, during a live game, can place a model into the world. (in a specific Folder)
When this happens, the clients detect a :ChildAdded event for that folder, and get a reference to the model.
Once the client has the model, I perform a :ScaleTo operation on the model to adjust it to the client’s settings.
At first the ScaleTo was happening too fast, and only some of the parts in the model were being scaled. So then I added a wait of 1 second after the ChildAdded event, before I called ScaleTo, and then the whole model was scaled correctly.
So I needed a way for the client to know when the entire contents of a model, placed down by the server are fully loaded so that I can perform things on it such as scale or color changes, etc…
Try using repeat task.wait until all parts exists.
Another solution is to put the model in workspace seconds before the event and position it further and then set it back to its old position when you are going to scale it.
Thanks for the suggestion, but I feel like ‘task.wait until all parts exist’ is the problem I’m having. If the client hasn’t gotten all the parts, how does it know if more parts are coming or if they are all loaded.
As for the second suggestion, I feel this is pretty much the same as having the task.wait, between the event and the scaling, where I need to choose an arbitrary number, such as 1 second, etc… I would rather find a solution (if possible) where the wait is only until the parts are loaded, so if you are on a laggy connection, it might take 500 ms, but someone with good ping it might take 5 ms, etc…
Well heres another suggestion, when you put the model in workspace, fire to all clients to load the parts inside using ContentProvidor, it will yield until all parts loaded inside the model.
You can apple a task.wait() function to wait for the model to finish loading.
local ContentProvider = game:GetService("ContentProvider")
local model = YourModelHere
local success, errorMessage = pcall(function()
ContentProvider:PreloadAsync(model:GetDescendants())
end)
if not success then
warn("Failed to preload assets: " .. errorMessage)
end
This may be a bit over doing the checking here but, it should be fast enough and it sure will wait for everything before you call the scaling… Maybe something like this will help.
local function modelLoaded(model)
for _, part in pairs(model:GetDescendants()) do
if not part.Parent then
return false
end
end
return true
end
folder.ChildAdded:Connect(function(model)
while not modelLoaded(model) do
task.wait()
end
model:ScaleTo(Vector3.new(1, 1, 1))
end)
It looks like the part I am not understanding is how you can do things such as model:GetDescendants, when the model is not even fully loaded.
Will it still give the correct results if you call GetDescendants on a model that is not totally replicated to the client yet? I would think it would only return the parts that had been replicated at the time of calling?
Becuse of this, it’s what’s in the model that may be slower to load as this trigged the function by being there. Of course I’m just speculating, don’t see why this wouldn’t take care of a problem like that totally.
I will try to use preload async, or at least try to print out some stuff, once I finish fighting with studio.
I go to test with 2 screens, and it puts the chat open right over my gui buttons, and it wont let me close chat … so frustrating
You should be able to run any Roblox game and the chat window will remain open, as you left it open. But if you close it, it will also stay closed when you open other Roblox games. More of a realtime user preference/setting than a game setting thing…
Between the two clients, instantly after the :ChildAdded event of the folder fires, one client 'at the time of calling the preload async, has less parts from GetDescendants that the other one.
Ok, I think I found a simple solution that works well for me.
What @5smokin said “fire to all clients to load the parts” it got me thinking… how could I have the server let the clients know how many parts to load?
Then I remembered that the server is adding an attribute to the model, with the players userid, so that the clients know who owns the model. So I thought why cant the server, just set an attribute with the “PartCount”, so the clients know how many parts should be in the model.
server
The correct way to do this is to set the models streamingtype to “Atomic”. This will ensure you dont get early access to the model without its children.
I just tested the solution by @Vundeq and it works perfectly. That is what I was looking for.
I also very much appreciate all the other ideas and suggestions, because they get me thinking of different things, so a thank you to all who contributed.