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 
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ā).