local Items = {}
local itemTable = {
["C_BasicWand"] = {Name = "Basic Wand", Rarity = "Common", Physical = Random.new(os.time()):NextInteger(1,3), Spell = Random.new(os.time()):NextInteger(3,8), Value = 1, Req = 1, Upgrades = Random.new(os.time()):NextInteger(3,10), CurrentUpgrades = 0},
["UC_BasicWand"] = {Name = "Basic Wand", Rarity = "Uncommon", Physical = Random.new(os.time()):NextInteger(1,4), Spell = Random.new(os.time()):NextInteger(5,11), Value = 1, Req = 1, Upgrades = Random.new(os.time()):NextInteger(6,15), CurrentUpgrades = 0},
["R_BasicWand"] = {Name = "Basic Wand", Rarity = "Rare", Physical = Random.new(os.time()):NextInteger(2,6), Spell = Random.new(os.time()):NextInteger(9,16), Value = 1, Req = 1, Upgrades = Random.new(os.time()):NextInteger(8,20), CurrentUpgrades = 0},
["E_BasicWand"] = {Name = "Basic Wand", Rarity = "Epic", Physical = Random.new(os.time()):NextInteger(2,8), Spell = Random.new(os.time()):NextInteger(15,26), Value = 1, Req = 1, Upgrades = Random.new(os.time()):NextInteger(14,25), CurrentUpgrades = 0},
["L_BasicWand"] = {Name = "Basic Wand", Rarity = "Legendary", Physical = Random.new(os.time()):NextInteger(3,10), Spell = Random.new(os.time()):NextInteger(24,50), Value = 1, Req = 1, Upgrades = Random.new(os.time()):NextInteger(10,40), CurrentUpgrades = 0},
}
local lootTable = {
{Name = itemTable.C_BasicWand, Chance = 55},
{Name = itemTable.UC_BasicWand, Chance = 40},
{Name = itemTable.R_BasicWand, Chance = 25},
{Name = itemTable.E_BasicWand, Chance = 15},
{Name = itemTable.L_BasicWand, Chance = 1},
}
local function returnSumOfWeight(lootTable)
local sum = 0
for _, item in ipairs(lootTable) do
sum = sum + item.Chance
end
return sum
end
local function getRandomItem(lootTable)
local randomNumber = math.random(returnSumOfWeight(lootTable))
for _, item in ipairs(lootTable) do
if randomNumber <= item.Chance then
return item.Name
else
randomNumber = randomNumber - item.Chance
end
end
end
function Items.PickItem()
local item = getRandomItem(lootTable)
return item
end
return Items
in this script you are able to get a random item from the itemTable and it works as intended but I want all of the stats of each item to be unique and random, however when i test the game I get the items and they have the same stats for each rarity example: rare item will have 5 physical and 3 spell, if i get another rare item it will also have 5 physical and 3 spell, i do NOT want this i want each item to have different stats how can i alter my script to make this happen? like right now it sets a random stat and then its that stat until i do another playtest i want it to be random every single time i get a new item