I don’t know the best way to explain this, but what I am trying to do is a randomized gun spawner, and it’ll spawn a randomized rarity of that gun. I have a module for just the rarities for the guns, and here is an example;
No no no, they are DIFFERENT weapons, in the module, those weapons are randomized with a server side script, it randomizes and choses a weapon, and then checks the Rarity module for that gun for the rarity, not a bunch of Elseifs. I am trying to figure out to randomize its rarity, of it being part of the module it required.
--Setup--
local RepStorage = game:GetService("ReplicatedStorage")
local RaritySettings = require(RepStorage.GunsSpawnInc.Settings)
local GunDetails = require(RepStorage['Guns.Config'].GunDetails)
local GunRarities = require(RepStorage['Guns.Config'].Rarities)
local GunRaritiesReC = require(RepStorage['Guns.Config'].RaritiesReCong)
function randomizeweapon()
local Guns = game.ReplicatedStorage.Guns:GetChildren()
local GunsRandom = Guns[math.random(1, #Guns)]
return GunsRandom
end
--Maths--
--local tr = randomizeweapon()
local Guns = game.ReplicatedStorage.Guns:GetChildren()
local GunsRandom = Guns[math.random(1, #Guns)]
if GunsRandom:IsA('Model') then
local RarityRandom = GunRarities[GunsRandom]
local mathsforrare = RarityRandom[math.random(1, #RarityRandom)]
local FindRares = GunRaritiesReC[mathsforrare]
local tlc = game.ReplicatedStorage.GunsSpawnInc.GunLight:Clone()
local tle = game.ReplicatedStorage.GunsSpawnInc.Emmit:Clone()
tlc.Color = FindRares
tle.Color = FindRares
local r = GunsRandom:Clone()
r.Parent = workspace
tlc.Parent = r
tle.Parent = r
end
You can see in line 18 I attempted @3rdhoan123 's solution, and this has not worked.
For the edit;
Ignore the function and --local tr = randomizeweapon()
this is just me testing something else, and this is no where near my issue, as the error points at line 18, which again, is the answer 3rd provided me with
Don’t do getchildren, you want to get a randomized rarity of a gun from a table right?
Require the module that has the rarities, then do: local Guns = require(game.ReplicatedStorage.GunRarities) – Basicaly just require your table of rarities.
To require the table
Next,
You want to randomize it via using the math.random on the table.
I don’t think we are on the same page, lets just deconstruct it.
local GunRarities = require(RepStorage['Guns.Config'].Rarities)
local RarityRandom = GunRarities[GunsRandom] --the GUN NAME being found in the MODULE the RANDOM gun CHOSEN
local mathsforrare = RarityRandom[math.random(1, #RarityRandom)] --CHOSING the rarities available under that guns NAME in the module
local FindRares = GunRaritiesReC[mathsforrare] --Getting the chosen rarities color
Guns random seems to be a Model on the if statement, then you specify in GunRarities[GunsRandom] as GunsRandom as a number value. (If that makes sence)
When you specified it in line 18, it was nil. I think.