Chances/Weight System Luck Boost

Hello!

does anyone know how to add luck multiplier/boost in a chances system?
heres my module :

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local units, crates, config = unpack(require(ReplicatedStorage.packages.units))

local Chances = {}

function Chances.getindexbychance(Table)
	print(Table)
	local TotalWeight = 0
	for _, data in pairs(Table) do
		if not data["rarity"] then continue end
		local chance = config.rarity_chances[data.rarity]
		if not chance then continue end
		
		TotalWeight += chance
	end

	local RandomChance = Random.new():NextNumber(0)
	local CurrentChance = 0   
	print(TotalWeight, RandomChance)
	for index, data in pairs(Table) do
		if not data["rarity"] then continue end
		local chance = config.rarity_chances[data.rarity]
		if not chance then continue end
		
		CurrentChance += chance
		if RandomChance <= CurrentChance then -- chance
			return index
		end
	end
end

return Chances

tanks

2 Likes

ive already tried by doing TotalWeight/ReplicatedStorage.luck.Value on the Random NextNumber but still doesnt work.

also the chances are number and not only decimals nuneber

Multiply the weight of the item to increase its “valid range”. You shouldn’t be changing anything about your aggregate number or total weight.

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