How to use values ​from one module script in another module script?

Viewed 28

Faced such problem: it is necessary to use values ​​from other module script in one module script. Both module scripts contain tables with float, boolean and string values. How in theory can this be done and is it possible at all? And if not, what are the alternative solutions? I read on the forum that this can be done, but how exactly was not explained anywhere. For example. One module script:

local characters = {
    ["CharacterOne"] = {
        ["Health"] = 100,
        ["InGroup"] = false,
        ["Eating"] = {"Fruit", "Meat"}
    };
    ["CharacterTwo"] = {
        ["Health"] = 260,
        ["InGroup"] = true,
        ["Eating"] = {"Meat"}
    }
}
return characters 

Two module script:

local food = {
    ["Fruit"] = {
        ["Saturation"] = 20,
        ["Price"] = 2
    },
    ["Meat"] = {
        ["Saturation"] = 50,
        ["Price"] = 7
    }
}
return food
1 Answers

The documentation for ModuleScripts tells you how to use them in other source containers: the require function.

So assuming that you've named your ModuleScripts Characters and Food respectively, and assuming that they are siblings in a folder, you could utilize the require function like this :

local Food = require(script.Parent.Food)

local characters = {
    ["CharacterOne"] = {
        ["Health"] = 100,
        ["InGroup"] = false,
        ["Eating"] = { Food.Fruit, Food.Meat }
    };
    ["CharacterTwo"] = {
        ["Health"] = 260,
        ["InGroup"] = true,
        ["Eating"] = { Food.Meat }
    }
}
return characters 
Related