Unable to iterate through table in module script?

I am trying to iterate through a hard coded table in a module script, but the module script is returning an empty table for some reason.

Here is the module script (shortened):

local Settings = {}

--[[
Datakey attributes:
	Ordered: Indicates whether data is stored in an ordered datastore
	Value: The default value that the players receive when they don't have any saved data
	Leaderboard: Whether or not that value should be shown on the player list
--]]

Settings.DataKeys = {
	["Kills"] = {
			["Ordered"] = true,
			["Value"] = 0,
			["Leaderboard"] = true
	},
	["Deaths"] = {
			["Ordered"] = false,
			["Value"] = 0,
			["Leaderboard"] = false
	},
	["Wins"] = {
			["Ordered"] = true,
			["Value"] = 0,
			["Leaderboard"] = true
	},
	["Losses"] = {
			["Ordered"] = false,
			["Value"] = 0,
			["Leaderboard"] = false
	}
}

return Settings

And here is a shortened portion of my other module script requiring and attempting to iterate through the table:

local Settings = require(script.Settings)
local DataKeys = Settings.DataKeys -- Get the keys table from the settings module
local DSS = game:GetService("DataStoreService")
local DataHandler = {}

function CreateValues(player)
	
	print("TEST") -- prints
	for key,setting in ipairs(DataKeys) do -- go through keys and settings
		print("ITERATING") -- never prints
	end
	print("TEST 2") -- also prints
end

I am not sure if it is the way I am structuring my table, requiring the table, or some obscure undocumented behavior I’m running into? Any help is much appreciated, thanks. The settings module script is parented to the main module script calling it.

1 Like

Your issue is the use of ipairs, ipairs works on tables with numerical indexes and not dictionaries. Switch to pairs instead.

3 Likes

Thanks, I’ll test this out when I get back. I assume this is the reason.

1 Like

No problem, and I didn’t mean to steal your thunder @sniper74will. My apologies

Lol, I didn’t have the thunder in the first place, yes I provided a solution, but your solution was much better.

1 Like