Why can't I reference a table in a table from my module script?

You can write your topic however you want, but you need to answer these questions:
I want to create a module script that has weapon animations held within tables. I then want to reference those tables with animations in a local script.

I keep on getting index nil with ‘Axe’.

Ive tried changing quite a few things but i simply dont understand why it isnt working. I’m not too well versed in module scripts so maybe the answer to the issue is simple.

Module Script

local combatAnims = {}
anims = {
	Axe = {
		["Idle"] = -- id here,
	},
}

return combatAnims

Local Script

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local repstorage = game.ReplicatedStorage
local combatAnims = require(repstorage:FindFirstChild("CombatAnimMod"))

print(combatAnims.anims.Axe["Idle"])

make sure you put the Full Path

local combatAnims = require(game.ReplicatedStorage:FindFirstChild("CombatAnimMod"))

I had set a variable to replicated storage so I wasn’t sure if I needed to.

local repstorage = game.ReplicatedStorage

Also another thing, make sure you add WaitForChild as the Client takes some time to Load Things

Both solutions sadly didn’t work for me.

Module:

local combatAnims = {}
combatAnims.anims = {
	["Axe"] = {
		["Idle"] = "123 I'm an ID" -- id here,
	}
}

return combatAnims

LocalScript:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local repstorage = game.ReplicatedStorage
local combatAnims = require(repstorage:WaitForChild("CombatAnimMod"))

print(combatAnims.anims.Axe["Idle"])
1 Like

Tysm this worked, Im sorry for wasting your time and I’ll make sure to remember the need to use the name of the module before the table.

1 Like

You can also do your table inside the module brackets so that you don’t have to reference the name of the module each time.

local combatAnims = {
	
	["anims"] = {
		
		["Axe"] = {
			["Idle"] = "123 I'm an ID"
		}
		
	}
	
	
}


return combatAnims

How would using this method affect this line of code? Im interested in knowing.

print(combatAnims.anims.Axe["Idle"])

It doesn’t affect. You can even print(combatAnims.anims.Axe.Idle)

I see. Thank you, this has been very informative for me :smiley:

1 Like

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