Hello , I wanted to make it so I can acess the settings from the setting modules In my maps but I tried everything and cant make it work!

Hello , I wanted to make it so I can acess the settings from the settings modules In my maps but I tried everything and can’t make it work! the Idea is each time there is a new map the script will take the settings and apply them to the game exemple the wait time will be changed from maps to maps and the ambience too the lighting etc , I tried to acess it but I get the error message :[ Attempted to call require with invalid argument(s). Line 28 ] the Maps are in ServerStorage In a Map Folder and the Main script In workspace.


local mp = game.ServerStorage.MapFolder
local SPY = game.Workspace.SoundPlayer

local MapsTable = {
	mp.Base ,mp.Volcano  ,mp.Spooky  ,mp.SpecialPart  ,mp.Internet   
}
local SoundTable = {
	SPY.Err
}
local lastMap = script.LastFloorNbre
local CMap = script.CuFloorNbre
local AMP = game.Workspace.ActiveMaps
--local SettingModule = require(MPSettings)

-----------------------------------------------------------------------------Main

while true do
chose =	math.random(1,#MapsTable)
	
	
		
if chose == lastMap.Value then  
		print("no")
		wait()
		
	else if chose ~= lastMap.Value then
			local MYmodule = mp:FindFirstChild(MapsTable[chose].MPSettings)
			local MPSB = require(MYmodule)
			print(MPSB.TimeToWait)
				wait(0.25)
			
			print(chose)
			print(MapsTable[chose])
			--nameofthemap = MapsTable[chose]
			mp:FindFirstChild(MapsTable[chose].Name):Clone().Parent = game.Workspace.ActiveMaps
		

			
			wait(0.25)
			AMP:FindFirstChild(MapsTable[chose].Name):Destroy()	
			lastMap.Value = chose
end
end
	
	
	
	SPY.Err:Play()
	
	
	wait()
	print("loop")
	
	end

The Settings Modules In each maps

local module = {
	["SoundAMB"] = 1;
	["LightingType"] = 1;
	["TimeToWait"] = 30;
	
}

return module


Sorry for bad grammar.

Every help Is Appreciated!

Any error message in console appearing when attempting to require the module & use its features?

Yeah at line 28 : Attempted to call require with invalid argument(s)

What’s the name of the ModuleScript?

The built-in function named “require” expects a string value to be passed as the first argument to it, with that string value pointing towards the name of the ModuleScript being imported.

The name of the module Is : MPSettings
image

local MYmodule = mp:FindFirstChild(MapsTable[chose].MPSettings).Name

I tried and it gave me this as an error code , its like If it was trying to acess a value Workspace.Maps3:27: attempt to index nil with ‘Name’

local MYmodule = mp:FindFirstChild(MapsTable[chose]):FindFirstChild("MPSettings")

1 Like

Now I have no clue it should have worked but now it says Workspace.Maps3:27: attempt to index nil with ‘FindFirstChild’

I see the issue.

local MYmodule = MapsTable[chose]:FindFirstChild("MPSettings")

Look at how you tabled the maps & at how you assigned the value to MYmodule.

1 Like

OMG YESS ! now it works ! looks like the issue was the other FindFirstChild

It was because you were referencing “mp” twice.

1 Like

You’re right too, FindFirstChild only works when a string value is passed as an argument to it, you were attempting to pass an instance to it.

1 Like
local mp = game.ServerStorage.MapFolder

local MapsTable = {
	mp.Base ,mp.Volcano  ,mp.Spooky  ,mp.SpecialPart  ,mp.Internet   
}

MYmodule = mp:FindFirstChild(MapsTable[chose].MPSettings)

MYmodule = game.ServerStorage.MapFolder:FindFirstChild(MapsTable[chose].MPSettings)

MYmodule = game.ServerStorage.MapFolder:FindFirstChild(mp.Base.MPSettings)

MYmodule = game.ServerStorage.MapFolder:FindFirstChild(game.ServerStorage.MapFolder.Base.MPSettings)

The above just goes a little into why it didn’t work before. Assuming “Base” was the selected map.

Yeah , how the script works is , its always a different map with different settings etc .