How to wait until a whole model is loaded?

Hi ! I’d like to know if there’s a way to wait until a whole model has loaded:

my example :

When I clone the map (model) it doesn’t instanly clone it, but instead has a small delay and sometimes when it’s not loaded fully, the player can just fall out of the map.

script :

local pos = {Vector3.new(0,0,0),Vector3.new(0,0,200),Vector3.new(0,0,400),Vector3.new(0,0,600),Vector3.new(0,0,800),Vector3.new(0,0,1000),Vector3.new(0,0,1200),Vector3.new(0,0,1400),Vector3.new(0,0,1600),Vector3.new(0,0,1800),Vector3.new(0,0,2000),Vector3.new(0,0,2200),Vector3.new(0,0,2400),Vector3.new(0,0,2600),Vector3.new(0,0,2800),Vector3.new(0,0,3000),Vector3.new(0,0,3200),Vector3.new(0,0,3400),Vector3.new(0,0,3600),Vector3.new(0,0,3800)}
		for i, player in pairs(Players:GetPlayers())do
			local clone = mapChosen:Clone()	
			clone.Parent = game.Workspace.CurrentlyLoaded
			clone:MoveTo(pos[i])
	    	print("Initiated map"..mapChosen.Name..i)
		    local char = player.Character
	    	-- ??? Wait for the map to load
			char.HumanoidRootPart.CFrame = clone.Spawn.CFrame
	     end

I’ve found a similar post, but some replies say that WaitForChild(“Model”) doesn’t actually wait for the entire model

so i’d like some help on this :sweat_smile:

1 Like

should I add a wait or something ? Sometimes it does this but other times no

I might be wrong, but I’m pretty sure Clone() will continue to execute until the function is done cloning, so the model will be finished cloning (for the server) when the code after it for teleporting players is ran.

I believe this issue is a result of network streaming? Do you have streaming enabled? Try setting Workspace.StreamingEnabled to true, and Workspace.StreamingPauseMode to ClientPhysicsPause. This will pause the local simulation for a player if they teleport somewhere and the parts near them have not streamed in for them yet, preventing them from falling through the world if they have a slow internet connection.

8 Likes

Ok thanks i’ll check this tomorrow thanks for the help

1 Like

thanks it works ! But it’s strange, I have a 1gbps wifi connection but it still lags on roblox

1 Like

Clone doesn’t yield the thread, it just creates a copy of the argument you pass, assuming that argument being valid.

1 Like

That is right. I may have used poor wording. I meant as in the function will execute until it is finished and any other script will not be running until it is done. So it wouldn’t cause any problems with somehow teleporting players before its done cloning, and it would instead be a replication timing issue.

Clone doesn’t yield as in getting task scheduled like a coroutine.

1 Like

If you used improper wording then you should at least bother to fix it, your wording still is wrong again which may confuse readers and lead to mid information spread.

I have already edited my reply and I don’t see anything wrong with my wording now. If you think there is anything wrong still, feel free to explain.

1 Like