Issue with dictionaries

-- // Services
local MPS = game:GetService(`MarketplaceService`)


-- // Detecting gamepasses owned for refunds
function ProductDetection.GamepassFinder(Player)
	local TempNumHolder = 0
	local Gamepasses={
		-- // HELIOS TRANSFER
		
		[91005462] = { -- // Glock-17 -- // ID for gamepass
			[`Credits`] = 12; -- // Refund amount
		};
		[91005925] = { -- // Medkit
			[`Credits`] = 28;
		};
		[91005287] = { -- // AK-106
			[`Credits`] = 36;
		};
		[91005741] = { -- // Stolen Keycard
			[`Credits`] = 48;
		};
		[91006231] = { -- // Scar
			[`Credits`] = 88;
		};
		[137432579] = { -- // Cupids-Shooter 
			[`Credits`] = 100;
		};
		[100146592] = { -- // Pumkinfier 
			[`Credits`] = 160;
		};
		[137431518] = { -- // Cupid Bow
			[`Credits`] = 180;
		};
		[148309083] = { -- // Landmine
			[`Credits`] = 300;
		};
		[137432694] = { -- // Cupid deal
			[`Credits`] = 352;
		};
		[91006054] = { -- // Minigun
			[`Credits`] = 360;
		};
		
		-- // ORISIS TRANSFER
		
		[176993464] = { -- // Stolen keycard
			[`Credits`] = 90;
		};
		[176993606] = { -- // Glock 41
			[`Credits`] = 30;
		};
		[176993713] = { -- // AK 12
			[`Credits`] = 45;
		};
		[177098304] = { -- // R870
			[`Credits`] = 150;
		};
	}
	for Item in next, Gamepasses do
		if MPS:UserOwnsGamePassAsync(Player.UserId,Item) then
			TempNumHolder += Item[`Credits`] -- find out whats wrong here
		end
	end
	return TempNumHolder
end

In this loop Item prints the ID correct which is the gamepass ID.
However, I cannot access the Credits underneath the Item.
When I try access Credits it prints this error:


Meaning it can not find the dictionary and only sees Item as a number instead of the dictionary…?

I should also state, this is ran via the server in a module script.

The issue you’re facing is with the way you’re trying to access the Credits value within the Gamepasses table. Instead of using Item[ Credits] , you should use Gamepasses[Item][ Credits] . Here’s the corrected code:

		if MPS:UserOwnsGamePassAsync(Player.UserId, Item) then
			TempNumHolder += Gamepasses[Item][`Credits`]
		end
	end
	return TempNumHolder
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.