So I have this script that selects a random item in the pets table but it prints the amount of characters the name contains rather than the actual name. An example of this would be "Selected 5". I am wondering how to change this to make it print the item name. An example would be "Selected Fire Sword".
local Pets = { rarities = {0.6,0.4}; pets = { { name="Part"; rarity="Rare"; }; { name="Part2"; rarity="Legendary"; }; }; }; local totalweight = 0 for _,v in ipairs(Pets.rarities) do totalweight = totalweight + v end local at = math.random() * totalweight for i,v in pairs(Pets.rarities) do if at < v then print(Pets.pets[i] .. " has been chosen!") break end at = at - v end
This seems like the obvious solution:
print(Pets.pets[i] .. " has been chosen!")
Change to
print(Pets.pets[i].name .. " has been chosen!")