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!
01 | local module = { |
02 | [ "Tier1" ] = { |
03 | [ "Cost" ] = 25 , |
04 | [ "Currency" ] = "Coins" |
05 | [ "Pets" ] = { -- {Rarity,Damage,Health} |
06 | [ "Duck" ] = { 40 , 1 , 15 } , |
07 | [ "Blue Duck" ] = { 20 , 2 , 40 } , |
08 | [ "Red Duck" ] = { 20 , 4 , 20 } , |
09 | [ "Purple Duck" ] = { 10 , 4 , 35 } , |
10 | [ "Green Duck" ] = { 10 , 3 , 50 } |
11 | } |
12 | } |
13 |
14 | } |
15 |
16 | return module |
You don't seem to know how modules work.
Modules are like classes, for example:
1 | local module = { } |
2 |
3 | return module |
Now you can add all sorts of stuff to that module
, which you then return:
1 | local module = { } |
2 |
3 | function module.helloWorld() |
4 | print ( "Hello, world!" ) |
5 | end |
6 |
7 | return module |
Now, you would do something like this:
1 | local m = require(game.Workspace.ModuleScript) |
2 | m.helloWorld() |
By the way, modules act like normal scripts. They, in fact, are. They just need to be executed (using the require()
function):
1 | local module = { } |
2 |
3 | function something() |
4 | print ( 1 + 1 ) |
5 | end |
6 |
7 | something() |
8 |
9 | return module |
^ This, alone, won't do anything. But, if you invoke it from another script like:
1 | 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.