Attempt to Index Nil with Module Script

So basically I have a module script storing all the sprites info but I can’t get that info through a script. My module script:

local module = {
	["Slummy"] = {
		["Sprites"] = {
			["Back"] = 0,
			["Front"] = 469008770
		},
	},
	["Eagler"] = {
		["Sprites"] = {
			["Back"] = 0,
			["Front"] = 469008770
		},
	},
	["Catepie"] = {
		["Sprites"] = {
			["Back"] = 0,
			["Front"] = 469008770
		},
	},
	["Woovey"] = {
		["Sprites"] = {
			["Back"] = 149369874,
			["Front"] = 0
		},
	},
}

return module

I can’t get the sprites from scripts using:

local backsprite = module["Sprites"]["Back"]

As it returns nil. Any help is appreciated.

local Sprites = Module["Sprites"]
local backsprite = Sprites["Back"]

or
Module.Sprites.Back

1 Like

It’s because you’re trying to index Sprites directly from the module when there is no index called Sprites. You most likely forgot to add the entity’s name.

It should be along the lines of module[entityName]["Sprites"]["Back"].

1 Like

On my script I indexed the entity’s name but it still returned nil.

Is it possible for you to post that section of the code?

Here is my other code:

local encounters = require(game.ServerScriptService.Encounters)
local issparkling = false
local elist = require(game.ServerScriptService.EmelionInfo)

script.Parent.Touched:Connect(function(hit)
	local rate = math.random(1, 12)
	if rate == 3 or rate == 6 then
	if hit.Parent:FindFirstChild("Humanoid")then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local data = game.ReplicatedStorage.PlayerData
			local playerdata = data:WaitForChild(player.UserId)
			local party = playerdata:WaitForChild("Party")
			local route = encounters["Route "..script.Parent.Route.Value]
local list = {}
local chances = {}
			for i=1, #route do
				table.insert(chances, #chances +1, route[i][1])
end
for thing, percentage in pairs(chances) do
	    for i = 1, percentage do
	        table.insert(list, thing)
    end
	end
		local choice = list[math.random(#list)]
			local emelion = route[choice][3]
			local issparkling = math.random(route[choice][2], 100)
			if issparkling == route[choice][2] then
				print("Sparkling")
				issparkling = true
			end
			local bs = player.PlayerGui.MainGui.BattleScene
			bs.Visible = true
			local pn1
			for i,v in pairs(party:GetChildren())do
				local pn = v.PN
				if pn.Value == 1 then
					pn1 = v.Name
				end
			end
			print(route[choice])
			local backsprite = elist[pn1].Sprites.Back
			local osprite = elist[tostring(route[choice])].Sprites.Back
			bs.YourEmelion.Image = backsprite
			bs.TheirEmelion.Image = osprite
		end
		end
end)

I figured it out! Thank you everyone for the help!

post the fix for future people