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

Using WaitForChild for DispersalScript?

Asked by 6 years ago

So I’m using this dispersal script. It basically disperses folders with assets to Workspace, StarterGui, StarterPack, ServerStorage, etc.

for n,o in pairs(script.Parent.Workspace:GetChildren()) do
    o.Parent = game.Workspace
end
for n,o in pairs(script.Parent.StarterGui:GetChildren()) do
    o.Parent = game.StarterGui
end
for n,o in pairs(script.Parent.StarterPack:GetChildren()) do
    o.Parent = game.StarterPack
end
for n,o in pairs(script.Parent.ServerStorage:GetChildren()) do
    o.Parent = game.ServerStorage
end
for n,o in pairs(script.Parent.ReplicatedFirst:GetChildren()) do
    o.Parent = game.ReplicatedFirst
end
for n,o in pairs(script.Parent.ReplicatedStorage:GetChildren()) do
    o.Parent = game.ReplicatedStorage
end
for n,o in pairs(script.Parent.StarterPlayerScripts:GetChildren()) do
    o.Parent = game.StarterPlayer.StarterPlayerScripts
end
for n,o in pairs(script.Parent.StarterCharacterScripts:GetChildren()) do
    o.Parent = game.StarterPlayer.StarterCharacterScripts
end

for n,o in pairs(script.Parent.ServerScriptService:GetChildren()) do
    o.Parent = game.ServerScriptService
end
for n,o in pairs(script.Parent.Lighting:GetChildren()) do
    o.Parent = game.Lighting
end
print('Assets Loaded')
for n,o in pairs(game.Players:GetChildren()) do
game["Teleport Service"]:TeleportToPlaceInstance(game.PlaceId,game.JobId,o)
end
script.Parent:Destroy()

I’m getting errors in the output saying “... is not a valid member of ReplicatedStorage” So I thought of using WaitForChild since the server might not have recognized the dispersal yet

Is there anyway I can edit this script to use WaitForChild or do I have to go through every script in the game and add WaitForChild?

Answer this question