Require Module Script based in condition?

My question is simple: can i require a module script based in condition?
example script:

local MS_config = nil
if index == 1 then
	MS_config = require(script:WaitForChild("ms1"))
else
	MS_config = require(script:WaitForChild("ms2"))
end

Yes you can, but why did you not trying it directly in studio before asking there ?

i’m trying, but the Module script 2 is giving error. So its not working.

It work for me, i just tested it by doing this:

Script

local index = 1
local MS_config = nil

local function CheckIndex()
	if index == 1 then
		MS_config = require(script:WaitForChild("ms1"))
	elseif index == 2 then
		MS_config = require(script:WaitForChild("ms2"))
	end
end

CheckIndex()
MS_config:Print()
index = 2
CheckIndex()
MS_config:Print()

Module 1

local ms1 = {}

function ms1:Print()
	print("ms1 Required")
end

return ms1

Module 2

local ms2 = {}

function ms2:Print()
	print("ms2 Required")
end

return ms2

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