Is it possible to get a items full set of children to a certain ancestor?

Old Question


Alright, I’ve made a communication module to interact with other modules and find modules, scripts and local scripts if I need to.


This is so I’m able to grab whatever script I need without needing to go through and grab a bunch of parents to get to the script. (i.e; game.ServerScriptService.MainControls.Server.Core.Commands.Script).


Every time I try to require the said script, it comes back as nil.



Thank you for any assistance you can give me.

The Question

My question is; is there a way to get a location of a item, say a script, and it’s ancestors up until say the game instance?

The Reason

The reason I ask this is because I’m attempting to make a system does this exact thing, however if there is a system for this… I don’t want to go through the time to create the system when there’s no point to it.

Thanks for any assistance you may give.

You can’t require a script/local script. That’s what module scripts are used for. Are you trying to return the actual script object?

1 Like

I figured that was the case.

Yes I am!

Attempt to return non-replicated Instances will be nil in result. What I mean by non-Replicated Instances is when the client created an Instance without using Remotes the FE(FilteringEnabled) will prevent it to replicate it to the Server like showing it to other clients and the current client so the instance will be only visible to the client who created it. This will make the Instance a non-replicated Instance. (Correct me if I’m wrong.)

Check out this article for more information: FilteringEnabled

The issue is that the ModuleScript works for both Server and Client, with this; I’m using my modules on the Server Side for everything. Plus, I’ve done the exact same thing but with Modules already. That’s why I believe it could potentially be done with normal scripts & localscripts that are located in ServerScriptService and are disabled.

I fail to see the value of this, but can’t you just store the scripts in a table and then just index them through your module?

local module = {}

module.Scripts = {scriptName = PATH.TO.SCRIPT}

return module

Then you can just retrieve them by:

local Module = require(CommunicationModule)
local script = Module.Scripts.scriptName
1 Like

The issue with this is, I need to be able to access all of my scripts through-out different modules, and other scripts themselves.

A good example would be; I need to access my Settings Module while also accessing my Functions Module inside my script. This is especially helpful if you need to insert a local script to a player to change something such as a camera or enabling/disabling the chat.

To give more insight into this, I’m currently working on a Admin system and the main reason I’m making this system is so I can clone a local script that’s disabled and inside a folder called LocalScripts that’s inside my Protocol Folder. I have to duplicate this script to a specific player and clone it to that person. However, I’m not certain I know what the finalized names of each folder will be… which means directories may change and there’s a lot of coding I’d have to go through and change.

If you want the module script to work across both client and server, you can just set up the table different depending on which script required it.

1 Like

I’m not entirely sure if this would help me on what I need, however I will look into this, I’ve re-worded my question. If you’d like to re-look at it.

You could make use of :FindFirstAncestor in a recursive function to build a table of all the object’s ancestors. I don’t think there are any built in functions to do this.

1 Like

To get the ancestors just do


Then just make it recursive.

local function GetParents(Instance)
    if not Instance.Parent then
        return {} -- Change the base case if you'd lile
        local Parents = GetParents(Instance.Parent)
        return table.insert(Parents,Instance.Parent)

Also I found this if you want to have the function return the values the other way around you can do this

function extend(t1, t2)
    return table.move(t2, 1, #t2, #t1 + 1, t1)
1 Like