Increasing Luck in My Weight System

hello everyone i have a probleme for my weight system i don’t understand for increas luck to my system

--all pets
local PetsModule = require(script.Parent)

return {
	Dog = PetsModule.new("Dog", 1.2, "Commun", 50),
	Cat = PetsModule.new("Cat", 1.5, "Rare", 30),
	Mouse = PetsModule.new("Mouse", 2, "Epic", 15),
	Bat = PetsModule.new("Bat", 3, "Legendary", 4.9),
	Bird = PetsModule.new("Bird", 5, "Mythical", 0.1)
}

--systeme
local pets = require(script.Parent.Pets)

local function getRandomWeight()
	local x, weight = 0, 0
	
	for _, v in pairs(pets) do
		x = x + v.Weight
	end
	
	local random = Random.new():NextNumber(0, x)
	for _, v in pairs(pets) do
		weight = v.Weight  --Before this post, I was looking for solutions
		print(weight)
		if weight >= random then
			return v
		else
			random -= weight
		end
	end
end

return {
	Callback = getRandomWeight
}

If you are increasing luck by integers (whole numbers), one way of ‘increasing luck’ is to simply roll the pet n times, where n is the luck multiplier, then taking the best result out of the rolls.

I’ll look into ways to have luck with non-integer values, and will get back to you

1 Like

You can apply the luck multiplier directly to each item’s weight each roll. I’d suggest creating a temporary table to put these modified values in when doing this.

for index, pet in ipairs(pets) do
	pet.Weight *= math.pow(luckMultiplier, index - 1)
end