For loop not working in ModuleScript

local tools = {
	["Hammer"] = workspace:WaitForChild("Robux"),
	["Saw"] = workspace:WaitForChild("Saw"),
	["Robux"] = workspace:WaitForChild("Robux")
}

local module = {}

module.Test = function()
	print("I've been called")
	for _, v in ipairs(tools) do
		print(v)
	end
end

return module

Dunno if it will fix it, but try replacing

for _, v in ipairs(tools) do

with

for _, v in pairs(tools) do
1 Like

It’s a dictionary, don’t use ipairs. Use pairs.

It’s working now, Thank you, I never knew the difference between pairs and ipairs lol

Hey what about my reply? >:(

Just kidding, good for you that your problem is solved.

1 Like

Regarding your edit, it doesn’t matter. The table can still be not part of the module itself.

My apologies lol, He replied first so i have to pick the early one xD

1 Like

To explain why this worked, the ipairs() iterator is purposed specifically for iterating over arrays (in numerical order), in Lua, arrays are tables which are indexed by sequential integers starting from 1. The pairs() iterator can iterate over arrays and dictionaries (although the order in which it does isn’t determinable), in Lua, dictionaries are tables which are indexed by custom values.

1 Like