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

How do I turn this module script I made into a random rarity / weight choosing system?

Asked by 4 years ago
Edited 4 years ago

Hi there! I am making a game with an egg hatching system, but I don't know how to turn this module script I made into a random rarity / weight choosing system. Can someone explain how to do this, and / or insert a script and explain the piece of script to me so I know what to script into my script and / or change it it fit your script? The script is a module script in the replicated storage.

Thanks For Your Time!

local module = {
    ["Tier1"] = {
        ["Cost"] = 25,
        ["Currency"] = "Coins"
        ["Pets"] = {-- {Rarity,Damage,Health}
            ["Duck"] = {40,1,15},
            ["Blue Duck"] = {20,2,40},
            ["Red Duck"] = {20,4,20},
            ["Purple Duck"] = {10,4,35},
            ["Green Duck"] = {10,3,50}
        }
    }

}

return module

0
LOL THAT IS UNBALANCED Elixcore 1337 — 4y
0
No its not :> NarwhalAndMe 141 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You don't seem to know how modules work.

Modules are like classes, for example:

local module = {}

return module

Now you can add all sorts of stuff to that module, which you then return:

local module = {}

function module.helloWorld()
    print("Hello, world!")
end

return module

Now, you would do something like this:

local m = require(game.Workspace.ModuleScript)
m.helloWorld()

By the way, modules act like normal scripts. They, in fact, are. They just need to be executed (using the require() function):

local module = {}

function something()
    print(1+1)
end

something()

return module

^ This, alone, won't do anything. But, if you invoke it from another script like:

require(game.Workspace.ModuleScript)

It will output 2 to the console.

Your question's answer: ... is contained in this question. Go read it, it's almost the same as yours. The first answer is written awesomely.

0
Thanks! I will look at the other question! NarwhalAndMe 141 — 4y
Ad

Answer this question