Yielding till a part has loaded successfully

Hi, I’m ProfessionalPlayer60, and this is my first post on the forum asking for help.

So, I’m making a furniture system based on an algorithm I’ve seen used in many games, in which the client has a copy of the furniture they own.
When the player places the furniture, this is what happens:

  1. Client “places” local copy of furniture at desired position

  2. Client fires remote function to server and tells the cframe and furniture name

  3. Server places furniture at cframe and returns the furniture model

  4. Client deletes local copy of furniture (which is present in workspace)

This way I can ensure instant feedback to the player and make it look to the player that nothing happened to their furniture.
Or so I thought.

There is an issue when the player has a laggy connection, that the part disappears temporarily and then reappears. I found out this that the server has sent the part, but it hasn’t been loaded in the client yet.

So, is there any way I can find out whether the part has been loaded or not? I would really appreciate it if you would help me.

Thanks,
Professional Out

1 Like

If you are using a MeshPart or SpecialMesh you can use this function to load the meshes at the start of the game. For CSG parts (unions) you will need to have the models loaded beforehand but there is no accessible asset id.

To load CSG parts I believe you can simply put a copy of the CSG part in the workspace and the model should be loaded. I’d experiment with making this invisible and or placing it very far away. You may also be able to delete the copy later but I’m not sure if that means it will stay loaded.

If you’re talking about parts with mesh, you can follow Hexcede’s solution, additionally you can call PreloadAsync on the furniture’s instance.

If you’re talking about other parts, it may be a timing problem, have a try at ChildAdded while using your solution so you can compare and see if it’s more accurate to what you wanted.

If you still have problems with rendering them, you can make a furniture queue per player by using PlayerGui, that way when you want to insert the furniture, you could try reparenting it to the workspace in both server and client, so it starts rendering on the client, even if it’s not instantly, but it doesn’t need to flicker it, while still keeping a reference to the furniture on the server. However this doesn’t seem pratical if you have a lot of assets.

1 Like

Well, thanks a lot! I’ll do this and then erase the client furniture after a set control time(say, 15 - 20 secs)

I found using:

repeat task.wait() until ParentName:FindFirstChild("ObjectName")

works brilliantly, but the only issue with it is, if the part never loads for some reason (which is rare but it could still happen), or if it takes too long–you could try implementing a timeout somehow.