Help with luck module

module.Luck = {
	{"Simple", Chance = 1/2,Color = Color3.fromRGB(255, 255, 255)},
	{"Common", Chance = 1/4,Color = Color3.fromRGB(239, 255, 206)},
	{"Uncommon", Chance = 1/8,Color = Color3.fromRGB(156, 255, 114)},
	{"Rare", Chance = 1/15,Color = Color3.fromRGB(71, 166, 255)},
	{"Fire", Chance = 1/25,Color = Color3.fromRGB(255, 128, 44)},
	{"Rage", Chance = 1/50,Color = Color3.fromRGB(217, 25, 25)},
	{"Legendary", Chance = 1/100,Color = Color3.fromRGB(255, 229, 29)},
	{"Crystal", Chance = 1/200,Color = Color3.fromRGB(171, 141, 200)},
	{"Neon", Chance = 1/400,Color = Color3.fromRGB(56, 255, 56)},
	{"Demonic", Chance = 1/1000,Color = Color3.fromRGB(106, 18, 18)},
	{"Galactic", Chance = 1/2000,Color = Color3.fromRGB(74, 110, 195)},
	{"Sus", Chance = 1/6900,Color = Color3.fromRGB(255, 64, 0)},
	{"Solar", Chance = 1/10000,Color = Color3.fromRGB(255, 249, 61)},
	{"Deathly", Chance = 1/5000,Color = Color3.fromRGB(67, 20, 21)},
	{"Godly", Chance = 1/20000,Color = Color3.fromRGB(255, 255, 255)},
	{"Solar : Flare", Chance = 1/25000,Color = Color3.fromRGB(255, 162, 48)},
	{"Fire : Raging Flame", Chance = 1/30000,Color = Color3.fromRGB(255, 39, 39)},
	{"Aquatic", Chance = 1/40000,Color = Color3.fromRGB(96, 133, 255)},
	{"Abysal", Chance = 1/100000,Color = Color3.fromRGB(137, 53, 255)},
}

module.Spin = function(luckTimes,player,final)
	local decimalPlaceMulti = 10000000000000 --allows for decimals, every 0 is 1 decimal place (so the limit right now would be 0.0000001)
	
	local number

	if luckTimes >=1 then
		number = Random.new():NextInteger(0, (100*decimalPlaceMulti)/luckTimes) -- We get a random number between 0 and 100.
	else
		number = Random.new():NextInteger(0, (100*decimalPlaceMulti)*luckTimes) -- We get a random number between 0 and 100.
	end
	
	number = number/decimalPlaceMulti
	local chosen = nil-- The item that will be chosen.
	for i, item in ipairs(module.Luck) do -- Iterate over each item
		if number < (item.Chance * 200) then -- If the number is less than the Chance, this is the chosen item.
			chosen = item
		end
	end
	
	if final == true then
		if chosen.Chance*200 <= 0.15 then
			script.Parent.Send:InvokeServer(chosen[1],chosen.Color,chosen.Chance)
		end
	end

	return chosen
end

The script sort of works, but i have a problem as want abysal to be the rarest ‘aura’, however the chance is actually based off the difference between the closest rarest aura and the closest less rarest aura. I really dont know how to fix this, so thanks for your help.

maybe you should look into a weighted luck system.

3 Likes

As mentioned by @WickdSuper, definitely use a weighted system. Floating point arithmetic can be quite dubious and unnecessarily complex.

Side note, abyssal*

2 Likes

Hi thanks for helping, do you know how i can get the chance from a weighted system?

The chance is equal to weight/sum of weights

2 Likes

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