NotACircle
(NotACircle)
November 26, 2020, 10:41pm
#1
So I made a module script to store types of materials
Module
local Materials = {
Enum.Material.Grass,
Enum.Material.WoodPlanks,
Enum.Material.Cobblestone,
}
return Materials
and I made a script to run it that picks a random material out the list
Script
local config = require(game.ReplicatedStorage.Modules.Materials)
local RandomMaterial = config.Materials[math.random(1, #config .Materials)]
print(RandomMaterial)
comes out with “attempt to get length of a nil value”
What did I do wrong?
funwolf7
(funwolf7)
November 26, 2020, 10:48pm
#2
This is because the module returns a table that contains all the materials, yet you are trying to index that table with Materials. You should just use #config
instead of #config.Materials
and that should fix it.
1 Like
NotACircle
(NotACircle)
November 26, 2020, 10:50pm
#3
I plan on having multiple tables under one module script so how would I reference the “Materials” table directly under that module script?
2 Likes
funwolf7
(funwolf7)
November 26, 2020, 10:55pm
#4
You will have to have it return a table that contains all the tables you want to use.
Example (this would replace the last line of the module script):
return {
["Materials"] = Materials,
}
1 Like