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

Wait for the current Roblox Studio Place to load?

Asked by 9 years ago

My plugin is having an error when a Roblox Studio Place loads because the

game.DescendantAdded

event is firing when parts are loading into the game the first time. It currently works on an empty place, but when the number of instances in the Place increase, it fires. Is there any way to wait for the Place to load? Simply waiting a few seconds would be pointless, because a slow computer could take longer then that, and it would inconvenience most users.

3 answers

Log in to vote
0
Answered by
jakedies 315 Trusted Moderation Voter Administrator Community Moderator
9 years ago

You can use the DataModel.Loaded event (I never actually tested it but I have seen it used):

Game.Loaded:wait(); -- Waits until the Loaded event fires
game.DescendantAdded:connect(function(child)
    print(child.Name .. " has been added.");
end);
Ad
Log in to vote
0
Answered by 9 years ago

Heres something I do for the game, I use the repeat until nil loop so that the script waits until it finds the requirements, let me show you an example;

repeat wait(0)until game and game:FindFirstChild("Workspace") --This repeats waiting until game loads, and game.Workspace is existant, might be a bit buggy though :P

That'll repeat until the game loads, and Workspace loads, but I just use the 'Workspace' coding as a just-in-case, and for game.DescentdantAdded, you can use it for multiple purposes, for instance, to check what type it is, or what its name is, let me show you an example;

repeat wait(0)until game and game:FindFirstChild("Workspace") --Heres a 'waiting' loop

game.DescentantAdded:connect(function(Object) --Here is our function
if Object:IsA("Part") then --Lets check if it was a Part that was added
print(Object.Name.." is a Part!") --Its a Part!
end --This end is to end the code for the 'if' statement
end) --And this end is to end the code for the game.DescentantAdded event/function

Now, if you want it to check the name, then;

repeat wait(0)until game and game:FindFirstChild("Workspace") --Heres a 'waiting' loop

game.DescentantAdded:connect(function(Object) --Here is our function
if Object.Name == "Part" then --Lets check if the name is Part
print("Its a Part!") -- It is?! :o
end --This end is to end the code for the 'if' statement
end) --And this end is to end the code for the game.DescentantAdded event/function

As you'll see, the game.DescentantAdded is very useful for all sorts of things! It just depends on how you use it, and the repeat until nil loop will repeat waiting until the game loads, and Workspace loads. Hope this helped!

Log in to vote
-1
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

Maybe try;

repeat wait() until #game.Workspace:children() == #game.Workspace:children() --Yes I know :children() is deprecated...

That's the best I can think of right now.

0
Didn't work. User#2263 0 — 9y

Answer this question