Attempting to make universal locals

So I’m attempting to make a local for a folder no matter where it is in the game. Here’s the script so far:

local MWFolder = game:GetDescendants("MainWorld")

if MWFolder.Parent == game.Workspace then
    print("MWFolder Found; Workspace")
end

if MWFolder.Parent == game.ReplicatedStorage then
    print("MWFolder Found; RepStorage")
end

Dev log doesn’t seem to be printing what I’ve told it to print. Does anyone know if I formatted this wrong or something?
615a017cbbce61891b611b4193495c91

GetDescendants returns an array of instances. An array doesn’t have a ‘Parent’
Also the format is
local MWFolder = workspace["MainWorld"]:GetDescendants()

I see. I’m trying to make a local for it so I can use it later, so would it be

local GameDescendants = game:GetDescendants()
local MWFolder = GameDescendants.Name = "MainWorld"

This doesn’t seem right, I’m not quite sure how to do this

I’m not trying to get the descendants of MainWorld, though. I’m trying to find the folder MainWorld wherever it is in the game. For example if I were to more it to replicatedstorage.

:GetDescendants as stated by @Blokav returns an array of the children.

So you’re adding a Name field to this array thus making it a mixed table.

You need to go through the table:

for _, descendant in ipairs(descendants) do
    descendant.Name = ""
end

Oh also :GetDescendants doesn’t take any arguments, so might as well remove the “MWorld” argument.

You could do something like:

local MWFolder = workspace:FindFirstChild("MainWorld") or game:GetService("ReplicatedStorage"):FindFirstChild("MainWorld")

I see. How would I turn this into a local though, so I can use it later? The ultimate goal of this is to pull things in and out of ReplicatedStorage, so I need to be able to reference the object no matter where it is.

You can use @Blokav’s solution or if you know where it will be parented first reference it from the initial parent and then parent it wherever you want.

Tried that, but when I reparent it the locals no longer work. If I say that MainWorld is a child of Workspace and I change the parent to ReplicatedStorage, the local won’t be able to find MainWorld in Workspace anymore.

If you assign an instance to a variable, the variable can still reference that instance if you change its parent.

local stuff = workspace.Thing
print(stuff.Parent) -- "Workspace"
stuff.Parent = game.ReplicatedStorage
print(stuff.Parent) -- "ReplicatedStorage"

Did you do it like this.

local part = game.Workspace.Part -- example
part.Parent = game.ReplicatedStorage
print(part.Parent)
part.Parent = game.Workspace

This works. You probably trying to access it from the service before it was added there.