Can't call function in module script

I tried to call a function from a module script and it gives an error called “Argument 2 missing or nil”

LocalScript:

local module = require(game.ReplicatedStorage.Drone)
local drone = game.StarterPlayer.StarterCharacter
local ContextActionService = game:GetService("ContextActionService")

local newDrone = module.new(drone)

ContextActionService:BindAction("Forwards", module.forward, false, Enum.PlayerActions.CharacterForward)

P.S. Yep, I used a metatable in module script.

3 Likes

Any reply would help, I’m stuck with this for now.

Try capitalizing local module to Module, if the same error occurs try debugging the second argument in BindAction.

Well it didn’t work, how do I debug it?

Edit: Is it about me adding a self to the function I am trying to run?

Is module.forward a value or a function? I would try printing the argument before using it in function.

Module.forward is a function. And I’ll try to print the argument out but how?

Edit: I printed it out and it says nil.

Oh then add () after module.forward

Does not work, I get an error saying: attempt to call nil value and when I print the function it says nil.

What is the function called inside the module script?

The function is called forwards, I made it forwards and I still get that error.

Edit: I meant I changed the name that I put in the binding action but I still get the error.

Edit 2: Whenever I remove the parentheses I get an error saying argument 2 missing or nil.

Is the argument is missing in BindAction or the function your calling?

It misses in the Bind Action but whenever I add the parentheses back It says attempt to call a nil value. Is this about me printing the function and getting nil?

Edit: I believe this is because I’m using OOP and adding self as an argument?

Your function probably requires values and this is where u put your values…
Exp: module.forward(button)
the button is an instance in this example that you want to transfer to the function in the module script.

Well my functions do have arguments but it also has an argument called “self”, do I need to add that?

Edit: I am still getting the error.

Can I have look at the module script you’re referring to? You can delete what’s inside the function if u want to keep it private.

This is the only function that I am trying to call for now:

Is the code is in same script?

It is not, the function is in a module script and I am trying to call it in a LocalScript.

Try game.ReplicatedStorage:WaitForChild("Drone") in your require() call.

Still getting the same error where I try to call the function.