MainModule attempt to call a nil value error

So I am making a script to require a module to clone objects into certain paths but I keep getting the same error of MainModule attempt to call a nil value. I do not know what I am doing wrong so I am posting this here to get some help

Server Script:

local CMDR = require(7551323026)

CMDR.Init()

Main Module:

local module = {}
function module.Init()
	local serverSideScripts = script.ServerScripts:GetChildren():Clone()
	serverSideScripts.Parent = game.ServerScriptService
	local localScript = script.client:Clone()
	localScript.Parent = game.StarterPlayer.StarterPlayerScripts
	local gears = script.Gears:Clone()
	gears.Parent = game.ServerStorage
	local serverban = script.ServerbannedPlayers:Clone()
	serverban.Parent = game.ReplicatedStorage
end
return module

error:
image

The error happens here:
local serverSideScripts = script.ServerScripts:GetChildren():Clone()
You can’t use :Clone() with GetChildren() because GetChildren returns a table.

Instead you would have to clone the parent that holds all the scripts.

Ok! But how can I clone the children in the folder though?

You can use pairs to loop through the GetChildren’s table and then clone one by one.

local StarterPlayerScripts = game:GetService("StarterPlayer").StarterPlayerScripts
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local module = {}

function module.Init()
    local localScript = script.client:Clone()
    local gears = script.Gears:Clone()
    local serverban = script.ServerbannedPlayers:Clone()

    for _, Child in ipairs(script.serverscripts:GetChildren()) do
        Child:Clone().Parent = ServerScriptService
    end

    localScript.Parent = StarterPlayerScripts
    gears.Parent = ServerStorage
    serverban.Parent = ReplicatedStorage
end

return module

is this what you want?

1 Like