RNG System Help

I want to make a RNG Game where you get (fake rbx) for rolling. But I don’t know how to make a RNG and this is how far I could get.
(ServerScriptService Script)

local r = game.ReplicatedStorage.Events

r.Roll.OnServerEvent:Connect(function(plr)
	plr.leaderstats["🎲 Rolls"].Value += 1
	local luck = math.random(1, 1000)
	game.StarterGui.Game.RollingFrame.Visible = true
	game.StarterGui.Game.RollingFrame.Chance.Text = tostring(luck).." in 1,000"
	game.StarterGui.Game.RollingFrame.Amount.Text = plr.Values.Base * luck
end)

I also want to show the “1 in ???” on the fifth number.
This is my leaderstats:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local values = Instance.new("Folder")
	values.Name = "Values"
	values.Parent = plr
	
	local rolls = Instance.new("NumberValue")
	rolls.Name = "🎲 Rolls"
	rolls.Value = 0
	rolls.Parent = leaderstats
	
	local RobuxDisplay = Instance.new("StringValue")
	RobuxDisplay.Name = " Robux"
	RobuxDisplay.Value = "0"
	RobuxDisplay.Parent = leaderstats
	
	local Robux = Instance.new("NumberValue")
	Robux.Name = "Robux"
	Robux.Value = 0
	Robux.Parent = values
	
	local multiplier = Instance.new("NumberValue")
	multiplier.Name = "Multiplier"
	multiplier.Value = 1
	multiplier.Parent = values
	
	local base = Instance.new("NumberValue")
	base.Name = "Base"
	base.Value = 1
	base.Parent = values
end)

Also after this works, I will make upgrades for the base! Help is appreciated!

So hey there!
I see that you got stuck on this problem just like me. Weeeellll heres a tutorial or concept video I dug up and found:

This video has a basic understanding of RNGs and like actually creates a well organized way with the types of “rolls” you can get. There is also another post that I made a long time ago about this might wanna check that out (probably not gonna help you compared to the vid):

I hope this helps. :slight_smile: have a great day

I’m unsure, but maybe you could assign a certain amount of numbers to each outcome for it to work? Like you could have it so 1, 2, 3, 4 and 5 would be a 5/1000 chance?

Also, you could create a variable outside of the function for amount of rolls and set it to 0 or nil. Then each time you roll, you increase it by 1. Then you use an if statement to check if it’s 5. Then you can reset it and create an invisible text label or use instance.new.

This video is long, but what part of the video to when is it talking about RNG? Are they talking about the RNG for the whole video? I might watch this tomorrow but if you can explain that a little more then I don’t have to watch the whole part.

1 Like

From the 5 minute mark to the 12:35 approx. is the main section. (Sry lol for not explaining correctly)
If you watch a minute before the 5 it like shows the “template” thingy for your rng rolls but really other than that not rly anything important. A small application of the rng is used after 12:35.

Now I have an error:
ServerScriptService.RollHandler:12: attempt to perform arithmetic (mul) on nil and number

Script is here, index is producing the error:

r.Roll.OnServerEvent:Connect(function(plr)
	plr.leaderstats["🎲 Rolls"].Value += 0
	local luck = 1
	for i = 1, 5 do
		local index = RarityService.chooseIndex(Rarities, luck)
		if i == 5 then
			print("Chosen rarity: "..index)
			plr.Values.Robux.Value += (tonumber(index) * plr.Values.Base.Value) -- Error Line
        else
		    print("Possible rarity: "..index)
		end
		wait(1)
	end
	--game.StarterGui.Game.RollingFrame.Visible = true
	--game.StarterGui.Game.RollingFrame.Chance.Text = "1 in "..tonumber(index[2])
	--game.StarterGui.Game.RollingFrame.Amount.Text = plr.Values.Base * luck
end)

Otherwise, it works.

Can I see what the RarityService returns?
Can you put a print before doing the line right after that printing the index?

it is return selectedRarity

I wouldn’t recommend you using the “Robux” name, I’m pretty sure it’s against ToS.

add a print(index) & print(plr.Values.Base.Value) right before the error line to understand what’s getting nil here.

its fake rbx though not real rbx

I know, I know, but still, this could be considered as a scam or whatever, Roblox doesn’t like people using this name.

I found nothing nil.
Screenshot 2024-10-13 at 10.35.37
btw 1 is the base value and RarityVI was chosen index

What about plr.Values.Robux.Value ? This must be it.

I made that value to not be visible to leaderstats, but I made a string to display big numbers
Do i use WaitForChild or whatever those are?

Maybe add a print statement to know what it equals to, according to the error message, it must be nil.

It prints “2” which is the amount I have in the value(not nil).

Oh, well, Isn’t the problem coming from the fact that you’re using tonumber() on a string (“RarityVI”) ?

i tried it earlier but it didnt work though
plr.Values.Robux.Value += (tonumber(index) * plr.Values.Base.Value)

I’m pretty sure you got confused with what you write but you’re currently trying to convert a string (index) into a number with tonumber, which is not possible.