Hi, I have happen to figure out that :GetDescendants() only works on workspace and no other services? I have searched and have not found anything helpful. Does anybody know why? Not even game:GetDescendants() works, to search through ALL services.
That’s not true GetDescendants() works on things other than workspace, but you don’t really want to get the descendants of the workspace in the first place as it’s really expensive, and will eventually cause lag to your game.
Why does game not work on :GetDescendants()? I have tried on other services like game:getSerivce(‘Players’) and it does not work there.
What is actually the problem? I just tried printing out all the Descendants of the game, and nearly 51k printed out in my game. So you sure its not working? and actually, is there any error in console?
Did it print anything from other services or from workspace only?
I said the Descendants of the game, and even in ReplicatedStorage it does. Can you show your code, how are you trying to use it?
It will work in all the services.
All it does is print the name of the service and not things inside of the service, this is the code i’m using.
for i,v in pairs(game:GetDescendants()) do print(v.Name) end
I think that using get decendants for the entire game isn’t going to work. Why would you need this in your game anyway?
That seemed to work fine for me.
Why do you need to loop through the game’s descendants anyways? Also, are you sure its not printing the descendants because the list I printed seemed long, and I couldn’t find out each and everything from that.
Originally I was going to use it for an Anti-Virus, but it only worked on workspace so I said hell with it and didn’t use that. But I just now want to know why.
The only thing I can think of is that, you’re output is probably having a low maximum output lines, so you probably aren’t able to view all the Descendants.
Experiment if this is just a problem with it not printing by doing
for i, v in pairs(game:GetDescendants()) do
if v:IsA("BasePart") then
v.Name == "RegisteredPart"
end
end
Like james said above me, print may be under a lot of stress having to print every single object name.
Insert some parts into certain services such as replicatedstorage, serverstorage, and other ones and see if they are renamed when this code plays.
GetDescendants works on any instance. It’s a method defined in the Instance class. Part of the reason that calling it on game may not work is due to security context levels. The command bar is not able to access certain services under the DataModel, and that may be causing it to error. If you want to test it under the DataModel, try the following.
for _, obj in ipairs(game:GetDescendants()) do
local success, result = pcall(tostring, obj);
if (success) then
print(result);
end
end
It could be that you can’t access/read from some services since they’re locked/can’t be read from - you might need to use a pcall
. Try out the below script to see if it prints the descendants
for _, Service in ipairs(game:GetChildren()) do
local Success, Descendants = pcall(function()
return Service:GetDescendants()
end)
if Success and Descendants ~= nil then
for __, Descendant in ipairs(Descendants) do
print(Descendant.Name)
end
end
end