Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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.

0
maybe add a wait time before teleporting the players PoePoeCannon 519 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

0
I tried that but it waited forever. Tybearic 18 — 6y
Ad

Answer this question