Getting the name from a local variable to module scripts

  1. What do you want to achieve?
    Can I enter the opponent’s name from modulescript from a local variable into the script?

I would like to search for “Knight” using the name found in enemyName, but I don’t know if I can do it. I tried this solution,

CombatSettings.Settings.Mobs[enemyName].Statistic.Health

but I only get nil ;/

  1. What is the issue?
    I don’t know if I can do this

  2. What solutions have you tried so far?
    Developer forum and documentation I didn’t find anything there

Snippet from script:

	local enemyName = spawnPoint:GetAttribute("EnemyName")
	local enemyModel = game.ServerStorage.Enemies[enemyName]
	
	local enemyHealth = CombatSettings.Settings.Mobs[enemyName].Statistic.Health
	local enemySpeed = CombatSettings.Settings.Mobs[enemyName].Statistic.Speed

Snippet from modulescript:

		["Mobs"] = {
			["Knight"] = {
				["Statistic"] = {
					["MaxHealth"] = 80,
					["Health"] = 80,
					["Speed"] = 20,
				},
				["Attacks"] = {
					["Attack1"] = { -- NORMAL HIT
						["HitBox"] = {
                                   ...

The variable to be able to be referenced from a module script has to be inside of it, so like

Module.Enemies = {your table}

I don’t understand how to use it and why I need a table for it. I just want to get my enemy’s HP, but I can’t do it directly…

The variable you showed is a table, and basically you set the variable like you how you would set functions in a module

But I can’t do as you wrote… Since I cannot use the opponent’s name in the table, in this case “Knight” only Knight must be obtained by the attribute which gives me a name enemy but if I use CombatSettings.Settings.Mobs[enemyName].Statistic.Health this just gives me pause and I want to know if there is any way he can choose this Knight

Make sure you’re using CombatSettings = require(path) and also print each step. Print CombatSettings, CombatSettings.Settings, CombatSettings.Mobs, enemyName to debug.