Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script can't use table from ModuleScript?

local MaterialArray = require(game.ServerScriptService.materials)

while true do
	local Material = MaterialArray[math.random(1, #MaterialArray)]
	if Material[3][script.Parent.Floor.Value] == true then
		script.Parent.BrickColor = Material[2]
		script.Parent.Material = Material[1]
		script.Parent.Material.Value = Material.Name
	end
end

Is giving me the following error: Workspace.OreTest.LoadScript:4: bad argument #2 to 'random' (interval is empty)

Module Script:

materials = {
--	[Material Name[Sting]] = {Texture[Enum], Color[BrickColor], {B[Bool], 1[Bool], 2[Bool], 3[Bool], 4[Bool], 5[Bool]}, BasePrice[Int], Tools[Bool], Duribilaty[Int], Speed[Int]},

	-- Buyable Materials
	["Wood"] = {Enum.Material.Wood, BrickColor.new("Cork"), {false, false, false, false, false, false}, 1, true, 10, 10},
	
	-- Mineable Materials
	["Coal"] = {Enum.Material.Slate, BrickColor.new("Black"), {true, true, true, true, false, false}, 2, false, 0, 0},
	["Stone"] = {Enum.Material.Slate, BrickColor.new("Smoky grey"), {true, true, true, true, true, true}, 1, true, 15, 9},
	["Iron Ore"] = {Enum.Material.Marble, BrickColor.new("Medium stone grey"), {true, true, true, true, true, false}, 2, false, 0, 0},
	["Copper Ore"] = {Enum.Material.Marble, BrickColor.new("Bright orange"), {false, true, true, true, false, false}, 1, false, 0, 0},
	["Diamond"] = {Enum.Material.Marble, BrickColor.new("Deep blue"), {false, false, false, false, true, true}, 20, false, 0, 0},
	
	-- Createable Materials
	["Iron"] = {Enum.Material.Slate, BrickColor.new("Medium stone grey"), {false, false, false, false, false, false}, 8, true, 15, 8},
	["Copper"] = {Enum.Material.Marble, BrickColor.new("Bright orange"), {false, false, false, false, false, false}, 4, true, 12, 9},
	["Steel"] = {Enum.Material.Marble, BrickColor.new("Medium stone grey"), {false, false, false, false, false, false}, 10, true, 30, 5},
	["Diamond coated Steel"] = {Enum.Material.Marble, BrickColor.new("Deep blue"), {false, false, false, false, true, true}, 30, true, 100, 4},
	
	-- Intermediate Materials (Materials made by crafting that are used for crafting)
	["Carbon"] = {Enum.Material.SmoothPlastic, BrickColor.Random(), {false, false, false, false, false, false}, 6, false, 0, 0},
	
	-- Special (Events / Codes / etc.)
	["Roblox / AlphaBlox Red"] = {Enum.Material.SmoothPlastic, BrickColor.new("Bright Red"),{false, false, false, false, false, false}, 0, true, math.huge, 10},
	["Roblox / Twitter White"] = {Enum.Material.SmoothPlastic, BrickColor.new("White"),{false, false, false, false, false, false}, 0, true, math.huge, 10},
	["Twitter Blue"] = {Enum.Material.SmoothPlastic, BrickColor.new("White"),{false, false, false, false, false, false},  0, true, math.huge, 10},
	["AlphaBlox Black"] = {Enum.Material.SmoothPlastic, BrickColor.new("Black"),{false, false, false, false, false, false},  0, true, math.huge, 10},
}

return materials

I would say more, but that is all I know.

2 comments

0

show me your module script. maybe u didn't make the module script return the materials?

0

Edited... now includes module script!

2 answers

✓ Accepted answer
local MaterialArray = require(game.ServerScriptService.materials)

local function dictLen(dict)
    local x = 0
    table.foreach(dictionary, function()x=x+1 end)
    return x
end

local DictLen = dictLen(MaterialArray)

while true do
	local Material = MaterialArray[math.random(1, DictLen)]
	if Material[3][script.Parent.Floor.Value] == true then
		script.Parent.BrickColor = Material[2]
		script.Parent.Material = Material[1]
		script.Parent.Material.Value = Material.Name
	end
end

local MaterialArray = require(game.ServerScriptService)

while true do
    local Material = MaterialArray.Materials[math.random(1, #MaterialArray.Materials)]
    if Material[3][script.Parent.Floor.Value] == true then
        script.Parent.BrickColor = Material[2]
        script.Parent.Material = Material[1]
        script.Parent.Material.Value = Material.Name
    end
end

2 comments

0

not entirely sure what im actually doing when making this but oh well

0

Does not work.

This discussion is preserved as it was. New answers, comments, and votes are closed.