Attempt to index a nil value (global 'PlayerData')

Hi, if anyone could help, that would be amazing. I’m trying to install ps-dispatch but getting this script error. Does anyone know how to fix this?

This is a screenshot of the part it indicates

I think PlayerData.job.name or PlayerData.job

Hi,

Based on your description, it seems the primary issue is that PlayerData is nil. This typically happens if the resource has been restarted, or if the script isn’t properly configured to initialize PlayerData when a player joins the server.

To resolve this, you should first ensure that PlayerData is correctly set at the player’s entry point. Here’s how you can do it for both ESX and QB frameworks:

  • For ESX: Ensure you are retrieving player data by using ESX.GetPlayerData(). This should be done in a context where it’s guaranteed that the player data is available, such as after the player has fully joined.
  • For QB: Use QB.Functions.GetPlayerData() to fetch the player data. Similar to ESX, make sure this is called at a point where the player is fully integrated into the server.

If you find that PlayerData.job.type is nil, it suggests that while PlayerData might be set, the job details are not being captured correctly. In such cases, checking PlayerData.job.name can serve as a temporary workaround to understand what job is assigned, but you will need to address why job.type is not available.

Double-check the script’s logic to make sure that all necessary player information is populated correctly during the initialization phase. If the issue persists, you may need to look into the scripts that handle job assignments and ensure they are triggered appropriately when players join.

Let me know if this helps, or if you have any further questions!