I want to know how to fix this error, the error is a simple attempt to index nil. The issue is on line 111, but in the output, it shows that the array is not nil, on the same line it throws the error.
The issue I don’t understand how to fix is in the image below:
The only solution I’ve tried so far for this is retyping where the error occurred thinking it was a typo.
Restarting Roblox studio thinking it was an engine bug.
Other than that, I can’t see the issue in the script.
The playerData[] is a dictionary that takes the player object and returns the player data of that player as a table.
How and where is the function being called?
It could be due to another unexpected bug elsewhere in the code that calls the function with incorrect arguments.
I’d suggest following the call stack in search of the culprit.
I found where player was passed nil, the player arg was not nil, it was accually the backpack arg. The function is called via a bindable event so other scripts can change and access player data.
My main question is: Why did playerData[player].backpacks print the valid result before causing an error.
The function had to have ran multiple times in order for that to happen. The output shows this behavior as there are multiple things printed. The function ran successfully once printing the expanded table showing gems, inventory and storage and the second time it ran playerData[player] was nil.
You can see where it printed nil was where the function ran successfully as it shows the same line.
The error then occurred within a different call to the function due to an invalid argument as shown by the nil in the output.
I suggested that the reason to this behavior lies elsewhere in your code as there is nothing wrong with the function.