Trying to concatenate a string to a referencing thing

I’m making a function that references a folder and then a string determines which child it should go to. I tried using 2 full stops to concatenate them together, but I can’t tell if I did something wrong or if I can’t concatenate strings and referencing things (whatever they are called).

Here is the script:

ReplicatedStorage = game.ReplicatedStorage
loaded_map = script.Parent.loaded_map.Value

local functions = {
    load_map = function (area, transition, transition_name, transition_description, transition_colour)
print (area.."loaded")
ReplicatedStorage.load_area:FireServer(area, transition)

game.Workspace.maps. .. loaded_map .. .Parent = ReplicatedStorage

    end;
};

return functions;
2 Likes

Try

local map = workspace.maps:FindFirstChild(loaded_map)
map.Parent = ReplicatedStorage

Instead of

game.Workspace.maps. .. loaded_map .. .Parent = ReplicatedStorage

If you want to reference a child you know is present under an instance, you use [] syntax.
For example: game.Workspace.maps[loaded_map].Parent.
The . syntax is really just syntax sugar for [""] also. (game.Workspace == game["Workspace"]).

Also, since it was also mentioned as a solution. Prefer to use FindFirstChild only when you aren’t sure the instance will be there and you’ll be handling the case where it’s not separately.

4 Likes

Only try this:

workspace.maps[loaded_map.Name].Parent = ReplicatedStorage

Ok it worked. I need to modify my script a bit because it looked for an instance called “none” which I’ll fix now. Thanks.