ServerScript doesn't see ModuleScripts

Hi! I’m trying to make a customization system. There are multiple ModuleScripts for each function. Buy, Equip, Remove and more. But the script doesn’t see the ModuleScripts in that moment somehow.

local Modules = {}

for i,v in pairs(ModulesFolder:GetChildren()) do --get modules --[[script.Module]]
	Modules[v.Name] = require(v) --add them to modules (table)
end 

game.ReplicatedStorage.AvatarCustomizationEvent.OnServerEvent:Connect(function(plr,Module,...)
	Modules[Module](plr,...,Settings)
end)

This is the error, I get:

My question: Why can’t the script see the modules?

Is your module table set up as intentional, have you checked it with a print statement?
I don’t understand the line Modules[v.Name] = require(v), if you are adding them to a table
wouldn’t you want Modules[#Modules+1] = require(v)?

1 Like

I tried it but it still says “attempt to call a nil value”

So I made the for loop say Modules[#Modules+1] = require(v) but it still doesn’t work

Is Module a string? Can you show us how you fire the remote event?

1 Like

They’re stored in a folder stored in the script
image

The firing script is stored in a button in the shop frame
image

This is where the RemoteEvent gets fired

	game.ReplicatedStorage[Settings.RemoteEventName]:FireServer("BuyArm",script.Parent.ProductName.Text)
	if player.OwnedArms:FindFirstChild(ProductName) then --if player owns it
		if FindFirstChildProductName.Value == false then --if not equipped, equip
			game.ReplicatedStorage[Settings.RemoteEventName]:FireServer("RArm",script.Parent.ProductName.Text)
			wait()
			game.ReplicatedStorage[Settings.RemoteEventName]:FireServer("EArm",script.Parent.ProductName.Text)

I hired a scripter to do this so I don’t know what the line says either. I’m sorry for being not able to tell what the code says

I don’t see anything named “RArm” in that folder.

1 Like

Oh god. I’m such an idiot. I renamed the scripts 1 or 2 days ago. Thank you very much. I should have known that. I’ll try it with that

It worked! Thank you so very much.

1 Like

I’m sorry for asking again and I’m sure you’re currently doing something else but I have an error again. So I changed the “ArmScript” code (the script in the frame which a button is in which you can click on and buy the arm) to the updated modulescript names

script.Parent.TextButton.MouseButton1Click:Connect(function()
	game.ReplicatedStorage[Settings.RemoteEventName]:FireServer("BuyArm",script.Parent.ProductName.Text)
	if player.OwnedArms:FindFirstChild(ProductName) then --if player owns it
		if FindFirstChildProductName.Value == false then --if not equipped, equip
			game.ReplicatedStorage[Settings.RemoteEventName]:FireServer("RemoveArm",script.Parent.ProductName.Text)
			wait() --debug
			game.ReplicatedStorage[Settings.RemoteEventName]:FireServer("EquipArm",script.Parent.ProductName.Text)
			player.IsStarterArm.Value = true
			player:WaitForChild("C_EquippedArms"):FindFirstChild(script.Parent.ProductName.Text).Value = true
		elseif player:WaitForChild("C_EquippedArms"):FindFirstChild(script.Parent.ProductName.Text).Value == true then --if the arm is equipped, unequip

but now there’s an error in “BodyCustomization” again. It says


now.
When I click on it, it brings me to this

(the second line)

Try printing Module and Modules.

print(Module)
print(table.concat(Modules,','))
1 Like

Alr it finds “Module” but it doesnÄt find “Modules”

  14:47:32.499    -  Server - BodyCustomization:80

Is line 80 the Modules table?

The Modules table is in line 70

No, I mean is line 80 this print line?

local ModulesFolder = script.CustomizationModules --line 69
local Modules = {}

for i,v in pairs(ModulesFolder:GetChildren()) do --get modules --[[script.Module]]
	Modules[v.Name] = require(v) --add them to modules (table)
	--Modules[#Modules+1] = require(v)
end 

game.ReplicatedStorage.AvatarCustomizationEvent.OnServerEvent:Connect(function(plr,Module,...)
	Modules[Module](plr,...,Settings)
	print(Module)
	print(table.concat(Modules,','))
end) --line 81

Yes. Modules gets printed out in line 80

Ok, can you try adding a print line here to see if there is actually something getting added?

for i,v in pairs(ModulesFolder:GetChildren()) do --get modules --[[script.Module]]
	Modules[v.Name] = require(v) --add them to modules (table)
	--Modules[#Modules+1] = require(v)

	print('added module named',v.Name)
end 
1 Like
  14:53:57.444  added module named EquipArm  -  Server - BodyCustomization:81
  14:53:57.445  added module named RemoveArm  -  Server - BodyCustomization:81
  14:53:57.445  added module named EquipEffect  -  Server - BodyCustomization:81
  14:53:57.445  added module named RemoveEffect  -  Server - BodyCustomization:81
  14:53:57.445  added module named BuyEffect  -  Server - BodyCustomization:81
  14:53:57.445  added module named BuyArm  -  Server - BodyCustomization:81

I guess we just have to debug now.

local ModulesFolder = script.CustomizationModules
local Modules = {  }

for i,v in pairs(ModulesFolder:GetChildren()) do --get modules --[[script.Module]]
	Modules[v.Name] = require(v) --add them to modules (table)
	--Modules[#Modules+1] = require(v)

	print('added module named',v.Name)
end 
print(Modules) -- ok can u tell me what it says here
game.ReplicatedStorage.AvatarCustomizationEvent.OnServerEvent:Connect(function(plr,Module,...)
	print(Module)
	print(Modules) -- also here

	Modules[Module](plr,...,Settings)
end)
1 Like