Need help with script

I decided to update an old game about limits and something went wrong. I completed this modul script for 4 hours with a friend, but then I realized that something was wrong. Is it possible to spawn an item with a chance from this list?

It works something like this:
[“Item Name”] = {“Item Displayname”, 5(chance), 96095042(item id), 1700(price)},

local limited = {
	{
		["Normal"] = {
			["Common Items"] = { -- from 1k - 5k robux
				["Rarity"] = "Common",
				["MinPrice"] = 1000,
				["MaxPrice"] = 5000,
				Items = {
					["Sorcus' Chair"] = {"Sorcus' Chair (1/20)", 5, 96095042, 1700},
					["The Tale of EPIC DUCK"] = {"The Tale of EPIC DUCK (1/25)", 4, 96095042, 3000},
					["Blue Pocket Pal"] = {"Blue Pocket Pal (1/25)", 4, 658757624, 2500},
					["Tee Vee"] = {"Tee Vee (1/25)", 4, 15857936, 2500},
					["Black Iron Commando"] = {"Black Iron Commando (1/20)", 5, 928908332, 1250},
				}
			},
			["Rare Items"] = { -- from 5k to 25k
				["Rarity"] = "Rare",
				["MinPrice"] = 5000,
				["MaxPrice"] = 25000,
				Items = {
					["Irish Gentleman"] = {"Irish Gentleman (1 / 100)", 1, 74937568, 10000},
					["Taco Launcher"] = {"Taco Launcher (1 / 100)", 35, 170903868, 7500},
					["Xanwood Fedora"] = {"Xanwood Fedora (1 / 30)", 3.33, 188695491, 5000},
					["Bombastic Antlers"] = {"Bombastic Antlers (1 / 50)", 2, 147144571, 8600},
				}
			},
			["Epic Items"] = { -- 25k to 100k
				["MinPrice"] = 25000,
				["MaxPrice"] = 100000,
				["Rarity"] = "Epic",
				Items = {
					["Ninja Necktie"] = {"Ninja Necktie (1 / 1k)", 0.1, 71429414 , 35000},
					["Red Ice Crown"] = {"Red Ice Crown (1 / 500)", 0.2, 193696583 , 25000},
					["Perfectly Legitimate Business Hat"] = {"Perfectly Legitimate Business Hat (1 / 5k)", 0.02, 19027209 , 85000},
				}
			},
			["Legendary Items"] = { -- 100k to 250k
				["MinPrice"] = 100000,
				["MaxPrice"] = 250000,
				["Rarity"] = "Legendary",
				Items = {
					["Fancy St. Patrick's Fedora"] = {"Fancy St. Patrick's Fedora (1 / 25k)", 0.004, 149594212, 150000},
					["Fiery Horns of the Netherworld"] = {"Fiery Horns of the Netherworld (1 / 30k)", 0.00333, 215718515, 200000},
				}
			},
			["Noob Items"] = { -- 250k to 1M
				["MinPrice"] = 250000,
				["MaxPrice"] = 1000000,
				["Rarity"] = "Noob",
				Items = {
					["Noob Attack: Bad Hair Day"] = {"Noob Attack: Bad Hair Day (1 / 100k)", 0.001, 30390398, 700000},
					["Noob Assist: Pizza Pal"] = {"Noob Assist: Pizza Pal (1 / 50k)", 0.002, 1402448461, 170000},
					["Noob Attack: Ninja Nuisance"] = {"Noob Attack: Ninja Nuisance (1 / 75k)", 0.00133, 27171057, 260000},
					["Noob Assist: Gingerbread Gratitude"] = {"Noob Assist: Gingerbread Gratitude (1 / 85k)", 0.00118, 2620416387, 500000},
					["Noob Attack: Raig Table Revenge"] = {"Noob Attack: Raig Table Revenge(1 / 125k)", 0.0008, 243853798, 900000},
					["Noob Assist: S'mores Snacker"] = {"Noob Assist: S'mores Snacker (1 / 75k)", 0.00133, 904518348, 250000},
					["Noob Attack: Fallen Artemis Fatality"] = {"Noob Attack: Fallen Artemis Fatality (1 / 75k)", 0.00133, 1744078238, 300000},
					["Noob Assist: Golden Shield Guardian"] = {"Noob Assist: Golden Shield Guardian (1 / 85k)", 0.00118, 833771311, 400000},
					["Noob Assist: Basketball Buddy"] = {"Noob Assist: Basketball Buddy (1 / 100k)", 0.001, 100929743, 700000},
				}
			},
			["Exotic Items"] = { -- 1M to 10M
				["MinPrice"] = 1000000,
				["MaxPrice"] = 10000000,
				["Rarity"] = "Exotic",
				Items = {
					["Telamonster: the Chaos Edge"] = {"Telamonster: the Chaos Edge (1 / 250k)", 0.0004, 93136746, 1000000},
				}
			},
			["Atomic Items"] = { -- 10M to 50M
				["MinPrice"] = 10000000,
				["MaxPrice"] = 50000000,
				["Rarity"] = "Atomic",
				Items = {
					["Lucky Doge"] = {"Lucky Doge (1 / 750k)", 0.0001333, 226189986, 100000000},
					["Archduke of the Federation"] = {"Archduke of the Federation (1 / 1M)", 0.0001, 293316452, 12000000},
				}
			},
			["Clockwork Items"] = { -- 50M to 250M
				["MinPrice"] = 50000000,
				["MaxPrice"] = 250000000,
				["Rarity"] = "Clockwork",
				Items = {
					["CW Ultimate: Amethyst Addiction"] = {"CW Ultimate: Amethyst Addiction (1 / 2,5M)", 0.00004, 188004500, 50000000},
					["CW Ultimate Wulfinite Will"] = {"CW Ultimate Wulfinite Will (1 / 3M)", 0.0000333, 286524947, 100000000},
					["CW Ultimate Ruby Rapture"] = {"CW Ultimate Ruby Rapture (1 / 5M)", 0.00002, 583635712, 200000000},
				}
			},
			["Darkhole Items"] = { -- 250M to 1B
				["MinPrice"] = 250000000,
				["MaxPrice"] = 1000000000,
				["Rarity"] = "Darkhole",
				Items = {
					["Business Cat"] = {"Business Cat (1 / 25M)", 0.000004, 121389389, 700000000},
				}
			},
			["!?!?!?! Items"] = { -- from 1B
				["MinPrice"] = 1000000000,
				["MaxPrice"] = 999909999999999,
				["Rarity"] = "!?!?!?!",
				Items = {
					["Dominus Vespertilio"] = {"Dominus Vespertilio (1 / 50M)", 0.000002, 96103379,1700000000},
					["Dominus Messor"] = {"Dominus Messor (1 / 150M)", 0.00000067, 64444871, 47000000000},
					["For the Ages: George Washington"] = {"For the Ages: George Washington (1 / 100M)", 0.000001, 46363291, 25000000000},
					["Dominus Astra"] = {"Dominus Astra (1 / 400M)", 0.00000025, 162067148, 995000000000},
					["Dominus Infernus"] = {"Dominus Infernus (1 / 175M)", 0.00000057, 31101391, 50000000000},
					["Dominus Rex"] = {"Dominus Rex (1 / 50M)", 0.000002, 250395631, 20000000000},
				}
			},
			["Tentacel Items"] = { -- from 100M
				["MinPrice"] = 1000000000,
				["MaxPrice"] = 999909999999999,
				["Rarity"] = "Exlusive Tentacel Group",
				Items = {
					["8 Bit Mr Tentacles"] = {"8 Bit Mr Tentacles (1 / 13M)", 0.0000077, 507795810, 100000000},
					["Santa Tentacles"] = {"Santa Tentacles (1 / 150M)", 0.00000067, 1223107595, 500000.000},
					["Mrs Tentacles"] = {"Mrs Tentacles (1 / 150M)", 0.00000067, 13416321, 200000000},
					["Tentacles Junior"] = {"Tentacles Junior (1 / 150M)", 0.00000067, 15054210, 500000000},
				}
			},
			["Domino Items"] = { -- from 2B
				["MinPrice"] = 1000000000,
				["MaxPrice"] = 999909999999999,
				["Rarity"] = "Exlusive Domino Group",
				Items = {
					["Domino Crown"] = {"Domino Crown (1 / 1B)", 0.0000001, 1031429 , 123123123123},
					["Viridian Domino Crown"] = {"Viridian Domino Crown (1 / 850M)", 0.000000118, 4390890198 , 100000000000},
					["Red Domino Crown"] = {"Red Domino Crown (1 / 750M)", 0.000000133, 42211680 , 50000000000},
					["Festive Domino Crown"] = {"Festive Domino Crown (1 / 500M)", 0.0000002, 2606192523 , 25000000000},
					["Bluesteel Domino Crown"] = {"Bluesteel Domino Crown (1 / 150M)", 0.00000067, 68258723 , 5.000000000},
					["Counterfeit Domino Crown"] = {"Counterfeit Domino Crown (1 / 100M)", 0.000001, 1560601706 , 2000000000},
				}
			}
		},
	}
}

function limited.Spawn()
end

return limited
2 Likes

Although the complex and long structure of your limited table, it is still possible to extract data from it.

print("Black Iron Commando Rarity: "..limited[1]["Normal"]["Common Items"]["Items"]["Black Iron Commando"][2])
print("Black Iron Commando Price: "..limited[1]["Normal"]["Common Items"]["Items"]["Black Iron Commando"][4])

If you were to redesign it to make it more simpler, I would recommend that you store these values as physical objects like String/NumberValues (inside Folders) within the game world (i.e. ServerStorage).

2 Likes

Yes, I understand that. But how can I spawn a random item from this list? With a chance

2 Likes

one way would be to assign each rarity a number rarity, example:

["Rarites"] = {
    ["Atomic"] = 0.01
    ["Legendary"] = 3.5
    ["Common"] = 100
}

common is set to 100 on purpouse, you’ll see in a second.
now how we’re gonna roll the chance would be using math.random, i usually like to keep this in a module somewhere so i can just access it anytime i want a random chance to be rolled.

the formula for this would be looping through all possible rarities from the lootbox / whatever you’re opening in order from most rare to most common, and then doing a math.random(RarityChance, 100)

let’s say RarityChance is like 3.5 (legendary), in that math.random it’d be math.random(3.5,100), right? not quite, this is the only problem with this, since math.random doesnt work with decimals.
you’d have to multiply both the 100 and the RarityChance (3.5 in this case) with a number that will remove the decimals, in this scenario 10, and then you’ll have math.random(35,1000), which is the same chance, and it works! now that the rarity is rolled, just choose a random item from that rarity / whatever the lootbox contains.

if all other rarities fail, it gets to the last one which should be 100, or in other words garaunteed, because if not there’d be a chance you open nothing from the lootbox.

adding stuff like luck modifiers would also be easy, just multiply RarityChance by the luck multiplier number.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.