Trying to create a loader script

Hello devfourm! I’m trying to create a loader script but I can seem to do it correctly, so for my new admin panel, I wanted to create a loader so once you inserted the model in your game whenever the play button is pressed it loads all of the folders from workspace to there respective places.


-- Define a mapping of folder names to their respective target locations
local targetLocations = {
    ["FusionX"] = game:GetService("ReplicatedStorage"),
    ["FusionXServer"] = game:GetService("ServerScriptService"),
    ["FusionXUi"] = game:GetService("StarterGui")
}

-- Reference to the parent folder containing the folders to be moved
local sourceFolder = game.Workspace:FindFirstChild("FusionXGold")

-- Check if FusionXGold folder exists
if not sourceFolder then
    warn("FusionXGold folder not found in Workspace")
    return
end

-- Function to move folders to their respective target locations
local function moveFolders()
    -- Loop through all children of the FusionXGold folder
    for _, item in pairs(sourceFolder:GetChildren()) do
        -- Check if the item is a folder and its name is in the mapping
        if item:IsA("Folder") then
            local targetLocation = targetLocations[item.Name]
            if targetLocation then
                -- Move the folder to its target location
                item.Parent = targetLocation
                print("Moved folder: " .. item.Name .. " to " .. targetLocation.Name)
            else
                print("No target location found for folder: " .. item.Name)
            end
        else
            print("Item is not a folder: " .. item.Name)
        end
    end
end

-- Call the function to move folders
moveFolders()

this is what my friend suggested but it didn’t work at all and I haven’t been able to get it working.

Thanks for reading!

I took this script into a folder in workspace and it worked perfectly. Could you show me the hierarchy of your folder?

Hey on mobile rn, the structure is FusionXGold a main folder that holds all the other side folders and the locater script is inside workspace with the main folder