How would I make some sort of 'directory' system using folders, accessible through strings?

To make it easier to understand, what I mean is having something like this in ReplicatedStorage;
image
And to access, for example, the BrickColor value in the f1 folder, use a function like
something("f1.Value1")
and to access the BoolValue in the Howdy folder, use something like
something("f1.Howdy.Value")

Basically just the normal way to get instances, but through a string, as the function is going to be the one actually getting the full path to the instances.
I can’t figure out any way to make something like this

I have this exact functionality in my game! I used this to make it (modified version):

local function FetchAsset(parent: Instance, name: string, separator: string?): Instance?
	if assets.cache[name] then -- if this directory was already used, just load the cached Instance
		return assets.cache[name]
	end
	
	local key = separator or '.' -- default url is "Parent.Child", but it can be customized to anything else (i.e "Parent/Child")
	local split = name:split(key) -- Splits the name up by the separator so it can locate each item separately
	local found = parent -- start from the root directory (should be an Instance)
	for _, n in split do -- loop through the split directory
		local f = found:WaitForChild(n,10) -- wait for a child to exist, for 10 seconds
		if f then
			found = f -- set the next directory to the current located child 
		end
        return nil -- child wasn't found, just return nil
	end

	assets.cache[name] = found -- save the child (cache)
	return found
end

Usage

local value1 = FetchAsset(<ROOT>, "f1.Value1") -- should return the instance
-- of course, this removes type analysis, so you would have to manually give it types
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.