How to make item RNG?

So I want to make a rng game where there is a selection of items and when you click roll and the item gets sent to a inventory but the problem is idk how to make a rng or inventory can anyone help me out?

1 Like

Is it like luck??? For the rng???

If yes,use a module script to start with

Local luck = 0

Also,use plugins to see,we love to copy other people codes

1 Like

I’m very new to coding, but this is fairly simple

First, you should add the item to whenever you want to add it, ReplicatedStorage, for example

Then, make a list of the said items, for example

potato = 1

fries = 3

Then, do the following:

local chance = math.random(1, 500)

The 1 represents the starting number of your script, while the 500 represents the ending point, or the limit where you don’t want to go further

Then, do the following:

if change == potato then

game["Wherever your tool is"]["Tool Name"]:Clone().Parent = player.Backpack

And it should be done! Note that this is an example to give rewards such as models, that are visible to the player. If you want to give a custom title or something of the sort, you’d have to add a few extra lines to do so. But this should work as an example to make an idea on how to make a RNG game

3 Likes

Yeah thanks now i just need to make a backpack gui lol

1 Like

The backpack is an inbuilt function of each player, the thing where your store your items and you can expand by pressing “º”

1 Like

No like a backpack system where you can open it and click equip and so on

2 Likes

ahh I see, well, good luck with your game and I hope it helped!

2 Likes

This is how I did RNG for a Sol’s RNG System. You might be able to use it for your own item RNG (scripts below explanation):

How the function works is it selects a random number between 1 and the rarity, so if the rarity is 100 then it would pick a random number between 1 and 100. Then it divides that number by the player’s luck (defaults to 1). If the value is <= 1 then that stat gets selected. It does that for all the rarities in the ChancesModule and then out of all the stats that you got less than 1 for it will return the rarest one’s index in the ChancesModule. Also I used Random.new() over math.random because Random.new() can go to higher numbers than math.random.

local random = Random.new()
local ChancesModule = require(SharedModules.ChancesModule)

local function selectRandom(plr)
	local lastIndex = 1

	for index,value in ChancesModule do
		if (random:NextInteger(1,value[2]) / plr.playerValues.Luck.Value) <= 1 and value[2] > ChancesModule[lastIndex][2] then
			lastIndex = index
		end
	end

	return lastIndex
end

ChancesModule looks like this (Index 2 is the rarity):

local Chances = {
	{"Common", 2, Color3.fromRGB(202, 202, 202), "bad rarity"},
	{"Uncommon", 4, Color3.fromRGB(132, 202, 116), "kinda bad"},
	{"Rare", 10, Color3.fromRGB(61, 64, 255), "wow so rare"},
	{"Epic", 25, Color3.fromRGB(141, 0, 202), "so epic"},
	{"Legendary", 50, Color3.fromRGB(255, 213, 0), "legendary????"},
	{"Mythical", 100, Color3.fromRGB(110,255,224),"no way its a mythical"},
}

return Chances
6 Likes

The highest number math.random can go to is 2147483647 and the lowest is -2147483647. For random.new I don’t know the highest number but I do know it can go a lot higher than 2147483647

I’ll just wanna tell you, that’s GENIOUS!!!1 I’ve been trying to find ways to make an RNG system like Sol’s but all I found was that weird weighted chance thingy that my brain couldn’t handle. Yours is much simpler and way easier to organize. THANK YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU

1 Like

Would be pretty funny to find out if there is a limit (Don’t get me wrong somebody probably already figured this out), but considering math.random() only takes up to 2^63-1 (in minus: -2^63-1), I don’t think it would go much higher than 10^93 (1 Trigintillion) / -10^93-1

There definitely is a limit, I just never did the testing to know how much the limit actually is. Haven’t seen anything on the devforum saying the limit either, but I do know that it is significantly higher than the limit on math.random (which is the 64 bit integer limit). How did you get the number 10^93 though?

No problem, if you have any more questions feel free to ask.

Thank you I can tweak this code to my liking very easily. Question for the scripts where to they go?

Just send me devforum messages if you have any questions, or dm x_dom.