Hello. I am working on an inventory system for a game prototype and my code is doing weird things. (Said every programmer ever)
So for whatever reason I’m getting an “attempt to index nil” error for some data for the slots that is being sent to the client from the server but when I print said data on the line above it, it prints just fine.
AddItemRemote.OnClientEvent:Connect(function(SlotIndex, SlotData, SlotLocation, AddMode)
local Location : Frame = UI:FindFirstChild(SlotLocation)
local Slot = Location:FindFirstChild(tostring(SlotIndex))
print(SlotData["StackCount"]) -- Prints data perfectly fine
Slot.StackCount.Text = tostring(SlotData["StackCount"]) -- throws error: "attempt to index nil with 'StackCount'"
Slot.Image = ImageIDs[SlotData["Item"]["ID"]]
end)
Probably should note that this code fires when an item is attempted to be picked up. It also adds the item to the inventory’s backend on the server just fine but when trying to display it in the UI it has this issue.
I have been staring at the code for like half an hour and cannot figure out what the issue is.
If anyone knows what the issue is or has any ideas I would very much appreciate it.
I know it was already mentioned, but it has to be that Slot is nil, so Slot.StackCount is failing. (or im reading it wrong)
Please print Slot and double-check it’s not that