Question on a Luck System

I’m making a small rng system, and I have a few questions on making a system that gives u better rng if u have better luck (numberValue).

  1. What should the luck formula be? Current Formula: ‘random:NextInteger(1, math.round(StatsFolder:FindFirstChild(statName).Value / player.leaderstats[“Luck Value”].Value))’
  2. If the player’s luck is at 2, if an rng item is at 1/2 chance, would it make that item guaranteed?
  3. What if the player’s luck is above the rarest item’s chance, would it break the game?

The way you have it set up is fine, :NextInteger has checks in place to be sure min and max don’t get mixed up.

--// Rarity is 1 in every X rolls.
--// Playerluck is Player has X times as much luck then normal.

function RNGCheck(PlayerLuck, Rarity)
    local Roll = random:NextInteger(1, math.round(Rarity/PlayerLuck)) -- Picks a random number
    
    if Roll <= 1 then
        return true -- Player wins!
    else
        return false -- Player loses!
    end
end

If a rng item has a rarity of 2 (1/2), and the player luck is 2 then yes it’s guaranteed.

This function will not be a reason for an error to occur unless you don’t pass in proper PlayerLuck or Rarity.

1 Like

But, what if we dont want it to be guaranteed?
That would make the gameplay loop dumb.

Current Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StatsFolder = ReplicatedStorage:WaitForChild("Stats")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")

local activateRoll = EventsFolder:WaitForChild("ActivateRoll")
local messages = EventsFolder:WaitForChild("Messages")

local totalStats = StatsFolder:GetChildren()

local random = Random.new()

local function RNGCheck(PlayerLuck, Rarity)
	local Roll = random:NextInteger(1, math.round(Rarity/PlayerLuck)) -- Picks a random number

	if Roll <= 1 then
		return true -- Player wins!
	else
		return false -- Player loses!
	end
end
local function getRandomRarity(player)

	for i = 1, #totalStats do
		
		if RNGCheck(player.leaderstats["Luck Value"].Value, totalStats[i]) then
			
			if StatsFolder[totalStats[i].Name].Value > 500 then
				
				messages:FireAllClients(player.Name .. " has gotten " .. totalStats[i].Name .. "! (1/" .. StatsFolder[totalStats[i].Name].Value .. ")", StatsFolder[totalStats[i].Name].Color.Value)
				
			end
			
			return totalStats[i]
			
		end
		
	end
	
	return StatsFolder["Common"]
	
end

activateRoll.OnServerInvoke = function(player)
	
	local t = {}
	
	for i=1, workspace.GameInfo.RollAmount.Value - 1 do
		
		table.insert(t, totalStats[math.random(#totalStats)])
		
	end
	table.insert(t, getRandomRarity(player))
	
	return t
	
end

Game to Test: https://www.roblox.com/games/16411724069/random-rng-game