Alright, I’ve made a communication module to interact with other modules and find modules, scripts and local scripts if I need to.
Reason
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).
Issue
Every time I try to require the said script, it comes back as nil.
Workarounds
None
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.
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.)
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.
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.
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.
local function GetParents(Instance)
if not Instance.Parent then
return {} -- Change the base case if you'd lile
else
local Parents = GetParents(Instance.Parent)
return table.insert(Parents,Instance.Parent)
end
end
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)
end