I am relatively new to JS.
The HTML side of the JS (The menu functions) is working fine.
I simply want to use Natives in JS, instead of in Lua because I don’t want to trigger a NUICallback every time I update a value.
Upon trying to use a FiveM Native in my JS;
$("#test-button").on("click", function () {
const ped = GetPlayerPed();
console.log(ped);
});
I am met with an error in the console:
fxmanifest:
fx_version 'cerulean'
game 'gta5'
lua54 'yes'
ui_page 'html/index.html'
shared_scripts {
'config.lua',
}
server_script 'server/server.lua'
client_scripts {
'client/main.lua',
'client/cl_functions.lua',
'client/cl_client.lua',
'html/js/script.js',
}
files {
'html/**/*.css',
'html/**/*.html',
'html/**/*.js'
}
If anyone knows what I might be missing/doing wrong, please let me know!
Cheers, CClark
Solution: Run the natives in a separate JS file that isn’t linked to the UI.
JS files linked to the UI (NUI), simply cannot use natives.
Javascript is global scope so passing variables between files won’t be an issue.
I was not missing any server files.