Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to wait in a script until a model is completely moved from ServerStorage to Workspace?

I'm creating a script where it cycles through maps and moves them from ServerStorage to Workspace, but when I move the player to the new map, they just fall through because it hasn't loaded yet.

while true do
	wait()
	while game.Players.NumPlayers < 3 do
		wait()
	end
	local MapRange = math.random(1, 3)
	local CityMap = game.ServerStorage.CityMap
	local ParkMap = game.ServerStorage.ParkMap
	local WarehouseMap = game.ServerStorage.WarehouseMap
	wait(5)
	if MapRange == 1 then
		script.gameInProg.Value = true
		local model = CityMap:Clone()
		model.Parent = game.Workspace
		print("loading map")
		child = #CityMap:GetChildren()
		repeat wait() until #model:GetChildren() == child
		print("done")
		teleportIntoMap(model)
		while script.gameInProg.Value do
			wait()
		end
		wait(10)
		model:Destroy()
		script.gameInProg.Value = false
		
	elseif MapRange == 2 then
		script.gameInProg.Value = true
		local model = ParkMap:Clone()
		model.Parent = game.Workspace
		print("loading map")
		child = #ParkMap:GetChildren()
		repeat wait() until #model:GetChildren() == child
		print("done")
		while script.gameInProg.Value do
			wait()
		end
		wait(10)
		model:Destroy()
		script.gameInProg.Value = false
	elseif MapRange == 3 then
		script.gameInProg.Value = true
		local model = WarehouseMap:Clone()
		model.Parent = game.Workspace
		print("loading map")
		child = #WarehouseMap:GetChildren()
		repeat wait() until #model:GetChildren() == child
		print("done")
		teleportIntoMap(model)
		while script.gameInProg.Value do
			wait()
		end
		wait(10)
		model:Destroy()
		script.gameInProg.Value = false
	end
end

Here's my script so far(not including the teleportIntoMap function because that isn't important. Right now I tried waiting for the children of the old and new model to match, but it just waits forever. Anyone got a way to wait until the model is completely moved? Thanks.

1 comment

0

maybe add a wait time before teleporting the players

1 answer

Well, you could do

game.Workspace:WaitForChild("Model Name Here")

Basically, it's waiting for the child to be in the workspace if that makes any sense at all.

1 comment

0

I tried that but it waited forever.

This discussion is preserved as it was. New answers, comments, and votes are closed.