fivem icon indicating copy to clipboard operation
fivem copied to clipboard

NetworkGetNetworkIdFromEntity and other entity natives error in usage with pcall

Open mcNuggets1 opened this issue 1 month ago • 2 comments

What happened?

They throw errors AND HALT code even when called with pcall which should suppress errors.

Expected result

Don't halt code

Reproduction steps

print(pcall(NetworkGetNetworkIdFromEntity(1))) print(NetworkGetNetworkIdFromEntity(1))

Importancy

Unknown

Area(s)

FiveM

Specific version(s)

FiveM

Additional information

No response

mcNuggets1 avatar Nov 15 '25 13:11 mcNuggets1

Also they throw errors without a proper stacktrace.

mcNuggets1 avatar Nov 15 '25 13:11 mcNuggets1

It throws an error because you are calling it incorrectly.

print(pcall(NetworkGetNetworkIdFromEntity(1)))

Written like this, NetworkGetNetworkIdFromEntity(1) is executed before the pcall call. Then pcall receives its return value and tries to run using that, but the first parameter of pcall must be a function reference so that pcall itself can call it and handle any errors. After that, you list the function’s arguments without calling the function, like this:

pcall(NetworkGetNetworkIdFromEntity, 1)

Dani4Web avatar Dec 05 '25 06:12 Dani4Web