Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script can't use table from ModuleScript?

Asked by 6 years ago
Edited 6 years ago
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.

0
show me your module script. maybe u didn't make the module script return the materials? starlebVerse 685 — 6y
0
Edited... now includes module script! AlphaGamer150 101 — 6y

2 answers

Log in to vote
1
Answered by
Zititus 40
6 years ago
Edited 6 years ago
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

Ad
Log in to vote
0
Answered by
Meqolo 78
6 years ago
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

0
not entirely sure what im actually doing when making this but oh well Meqolo 78 — 6y
0
Does not work. AlphaGamer150 101 — 6y

Answer this question