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.