Error "attempt to call a nil value" on the client when calling the module

Client:

local clientScriptSpeedAbilitiesModule=loadMouleFunction:InvokeServer(assetIdModule)
--warn(clientScriptSpeedAbilitiesModule)--Debug
if not clientScriptSpeedAbilitiesModule then return end
UIS.InputBegan:Connect(function(input,gameProcessedEvent)
clientScriptSpeedAbilitiesModule.inputBegan(input,gameProcessedEvent,character,initialSizeX,speedLineFrame)

Server:

loadModuleFunction.OnServerInvoke=function(player:Player,assetId:number)
	local success,module=pcall(function()
		return require(assetId)
	end);if not success then return nil end
	return module
end

I call the client module from the client by AssetId on the server and then return the values ​​to the client. For some reason, an error appears: attempt to call a nil value when joining the game and subsequent clicks on the button.

3 Likes

My best guess is that whatever MainModule you require()'d didn’t have the functions you were trying to use. Make sure to check what index of the given module caused the error.

Also, unless you plan to make a Script Builder game, you should NEVER let the client tell the server what module ID to require or what code to execute, as that could easily be abused by exploiters to ruin your game.

In the case this isn’t a Script Builder game, you should instead have this required module be integrated with your game by parenting it to ReplicatedStorage, as it can be indexed by both the client and the server, with the server capable of automatically replicating changes to the service and its descendants to clients.

Could you post the module script that contains the function you are trying to call?

1 Like

The idea of ​​integrating with ReplicatedStorage is not bad, I will try it.

The module was already published, this would not work if the module was not published.

1 Like

I meant “post” as in post it in this thread for us to read.

I wouldn’t like to open the source code of the module, besides it is quite large.

I tried to integrate the module into ReplicatedStorage but it didn’t help, same error.

I tried to use debug messages but didn’t find any errors.

Well, I don’t know how to help you if you can’t/don’t want to post it here, considering this is an error due to calling a function that doesn’t exist in the module. Are you sure the function is exactly named “inputBegan” and was defined with a period rather than a colon?

Client:

UIS.InputBegan:Connect(function(input,gameProcessedEvent)
	warn(clientScriptSpeedAbilitiesModule.inputBegan)--output nil
	clientScriptSpeedAbilitiesModule.inputBegan(input,gameProcessedEvent,character,initialSizeX,speedLineFrame)--this line causes an error

Module:

function module.inputBegan(input,gameProcessed,character,initialSizeX,speedLineFrame)

Why don’t you place this module in server storage or replicated storage?

I call it by assetId, the location of the module is not important here. If I understand correctly, the location is not taken into account when publishing a module.

I call the module from the server, from ReplicatedStorage, technically the module is located where it is called, the result is the same.

No, I’m asking why you’re going through the hassle of publishing the module and getting its asset id when you can leave It in the game. Are you doing this for security reasons?

1 Like

I do this because I may in the future publish my system in the open access with closed source code, for this I use assetId.

Everything should work, but for some reason the script does not initialize the functions inside the module, which is why they are nil.

1 Like

Oh yeah I forgot you cannot pass functions through remote functions or events.


Remote Events and Callbacks | Documentation - Roblox Creator Hub

2 Likes

Yes, I forgot about that… So how do I pass functions across the client-server boundary

1 Like

It explicitly says you cannot pass functions… Why don’t you fire the arguments to the server that will be passed to your module? I’m not really sure if your module is entirely client based though

I’ll try to do it.(I am writing this message due to restrictions)

Btw quick tip, you cannot pass the input object from the client from the server btw so you’ll have to rework some things. If your module just checks for keycodes then just pass the keycode instead of the input object

It worked. Thank you.(I am writing this message due to restrictions)