Randomizer
Module MathInstall the module
Go on github then install the source code. After this, import it on roblox studio, preferally on ReplicatedStorage.
Use the module
Create a script, (preferably a localscript but both work), you will need to require the script with a path. The path is where the instance is. For example if your module is on replicatedStorage, you can type game:GetService("ReplicatedStorage").audioManager
if the module is on a folder named "Modules" which is on ReplicatedStorage then game:GetService("ReplicatedStorage").Modules.audioManager
. Now that you know how to get an instance's path, you will need to create a variable and require() the module.
local module = require(path.to.module)
local module = require(path.to.module)
It's not harder than that. You can now create another variable with value module()
to create a random function.
local module = require(path.to.module)
local random = module()
local module = require(path.to.module)
local random = module()
Mehod Parameters
You will need to create a parameter to create a custom random. First create a table inside module()
. This mean this will looks like this:
local module = require(path.to.module)
local random = module({})
local module = require(path.to.module)
local random = module({})
Then in this table. You can create any random thing you want. To create one, recreate an other table module()
in this table, you have two option that must be used: percentage
& callback
. Percentage is the chance to return the callback. You can create multiple one, like this:
local module = require(path.to.module)
local random = module({
{percentage = 50, callback = "It return option A!"};
{percentage = 50, callback = "It return option B!"};
})
print(random)
local module = require(path.to.module)
local random = module({
{percentage = 50, callback = "It return option A!"};
{percentage = 50, callback = "It return option B!"};
})
print(random)
This will print a random thing between "It return option A!" & "It return option B!". You can also create function:
local module = require(path.to.module)
local random = module({
{percentage = 50, callback = function() print("It return option A!") end};
{percentage = 50, callback = function() print("It return option B!") end};
})
random
local module = require(path.to.module)
local random = module({
{percentage = 50, callback = function() print("It return option A!") end};
{percentage = 50, callback = function() print("It return option B!") end};
})
random
Here is an example of printing 10 times random:
Credits
Here is every user contributed on audioManager's documentation