Wanted level command

So I am trying to get into LUA scripting on FiveM. I tried to make a basic set wanted level command. However, it always sets my wanted level to 5 instead of the arguments I give with it.

Something wrong with my code?

RegisterCommand('wanted', function(source, args)
    local level = args[1]
    SetPlayerWantedLevel(PlayerId(), level, false)
	SetPlayerWantedLevelNow(PlayerId(), false)
end)

Change

local level = args[1]

to this:

local level = tonumber(args[1])

It’ll convert the ā€œstringā€ argument into an actual number. Some natives seem to don’t care if you enter a string or a number when it’s specified as an ā€œintā€ parameter, but other natives are really picky.

1 Like

Thanks for explaining. This works.
Now another question, why do I have to put the [1] after the ā€˜args’ parameter? I don’t see why this is actually needed. Are all paramaters generated to arrays or something?

Exactly that :wink:
They are stored in a array/list (I believe space separated), so [1] will be the 1st argument after the /command
(example: args[1] = ā€œhiā€ >>> /command hi there args[2] = ā€œthereā€).