Error when trying to use QBCore.Commands.Add

If I run the Command specified in this function, I get this error:
SCRIPT ERROR: @qb-core/server/commands.lua:31: attempt to call a nil value (upvalue ‘callback’)

my code looks like this:
Server side:

local QBCore = exports[‘qb-core’]:GetCoreObject()

QBCore.Commands.Add(“MyCommand”, false, function(source)
local src = source
TriggerClientEvent(‘Command’, src )
end)

Client Side:

someotherstuff…

Public Main()
{
EventHandlers[“Command”] += new Action<string, bool>(TargetFunction);
}

someotherstuff

private void TargetFunction(string param1, bool param2)
{
Menu.Toggle();
}

The code which it references in the error looks like this:

function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, …)
local restricted = true – Default to restricted for all commands
if not permission then permission = ‘user’ end – some commands don’t pass permission level
if permission == ‘user’ then restricted = false end – allow all users to use command

RegisterCommand(name, function(source, args, rawCommand) -- Register command within fivem
    if argsrequired and #args < #arguments then
        return TriggerClientEvent('chat:addMessage', source, {
            color = {255, 0, 0},
            multiline = true,
            args = {"System", Lang:t("error.missing_args2")}
        })
    end
    callback(source, args, rawCommand)
end, restricted)

I know im using the function incorrectly, I just cant locate the error I made.

Update: I failed to use the syntax of the function which gave me this error.
I also executed the Command from the TXAdmin Console, which then returned the source to be zero, which gave me another error.

Because of that i was irritated and didnt focus on the main problem: The syntax errors.

To the team that develops QBCore:

It would be nice to have some Documentations on how to Add/Register Commands with your Core functionality.

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