solareon / slrn_qbmultijob

An LB-Phone app for managing multijob in QB-Core
GNU General Public License v3.0
3 stars 2 forks source link

attempt to index a nil value (local 'Player') and other. #4

Open SL-Cortez opened 4 months ago

SL-Cortez commented 4 months ago

Summary

I receive this error everytime the server restarts https://i.imgur.com/MHE14xv.png. Another thing the app was working fine for like an hour and then decide to switch jobs and I receive this error in the f8 console didnt mess with nothing after succesfully installing and testing it for like 10 mins. https://i.imgur.com/eoir0fb.png

Reproduction

https://github.com/solareon/slrn_qbmultijob/assets/170153861/1834e1e5-d6c4-4a82-94f7-3092feb08d09

Expected behavior

Expected to go off duty, switch jobs when clicking 'SELECT', Removed to jobs to be actually removed.

Actual behavior

Video above shows everything in detail what exactly happened.

Additional context

Pictures of the errors. https://i.imgur.com/MHE14xv.png https://i.imgur.com/FFZRBrc.png

Current Version

1.0.0

Custom Resources

LB-Phone

solareon commented 4 months ago

Are you running any sort of anti cheat or something that encrypts the net events? That code segment is failing at trying to grab the player object to get their jobs which is odd since that callback doesn't send any data from client to server so the only variable it needs is the source.

SL-Cortez commented 4 months ago

As of matter of fact I am running an anti cheat we are using FiveGuard Anti Cheat on our server. You think it could be that that’s causing it to break?

solareon commented 4 months ago

That could be causing an issue. Almost all fivem anti-cheats work by just obscuring netevents and export names to break injector menus. I don't know the particular syntax for it but you might need to add this resource to the exclusion list or maybe redo the install for the resources.

SL-Cortez commented 4 months ago

I can try to give this a try then later today since I’ll be headed to work for the day. I’ll stop the anti cheat and see what it does.

SL-Cortez commented 4 months ago

Well update: I disabled my anti cheat and gave it another go and nothing... does the same thing still.

solareon commented 4 months ago

Interesting. Right below that callback can you put a lib.print.error(source) and see if it prints your player id when opening the menu.

SloppyShovel commented 4 months ago

The reason the player is nil is because the load event gets triggered as soon as the resource is created this means the player hasn't spawned yet,

You can get if GetParentResourceName is defined to see if it's getting loaded into lb-phone iframe, to prevent slrn_qbmultijob from calling the load event on creation.

Add the following line above the loadJobs post request to block the event from loading outside of lb-phone.


if (typeof GetParentResourceName === "function") {  return }

$.post('https://slrn_qbmultijob/getJobs', JSON.stringify({}), function(data) {
  loadJobs(data);
});
solareon commented 4 months ago

@SL-Cortez can you try the updated version with @SloppyShovel's fix.

SL-Cortez commented 4 months ago

@solareon Just tried and downloaded the updated version. I still receive the F8 console error https://i.imgur.com/5eyreqz.png when I try to switch jobs. Tried to remove jobs as well they disappear but when I close the app and open it back up they are still there.

SloppyShovel commented 4 months ago

@solareon Just tried and downloaded the updated version. I still receive the F8 console error https://i.imgur.com/5eyreqz.png when I try to switch jobs. Tried to remove jobs as well they disappear but when I close the app and open it back up they are still there.

The fix is not related to the error you are getting, the fix only patches the Player is nil error, the issue you are having is most likely related to job configuration.

the failed to fetch means the RegisterNUICallback never returned a callback which in turn means the server callback never returned and most likely you have an error server side.