Rarity system not working

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cloverEvent = ReplicatedStorage:WaitForChild("Clover")

local luckMultipliers = {
	[1] = {
		changeToGet = 1,
		multiplier = 1
	},
	[2] = {
		changeToGet = 0.6,
		multiplier = 1.1
	},
	[3] = {
		changeToGet = 0.4,
		multiplier = 1.2
	},
	[4] = {
		changeToGet = 0.3,
		multiplier = 1.3
	},
	[5] = {
		changeToGet = 0.25,
		multiplier = 1.4
	},
	[6] = {
		changeToGet = 0.2,
		multiplier = 1.5
	},
	[7] = {
		changeToGet = 0.15,
		multiplier = 1.6
	},
	[8] = {
		changeToGet = 0.1,
		multiplier = 1.7
	},
	[9] = {
		changeToGet = 0.09,
		multiplier = 1.8
	},
	[10] = {
		changeToGet = 0.08,
		multiplier = 1.9
	},
	[11] = {
		changeToGet = 0.07,
		multiplier = 2
	},
	[12] = {
		changeToGet = 0.06,
		multiplier = 2.1
	},
	[13] = {
		changeToGet = 0.05,
		multiplier = 2.2
	},
	[14] = {
		changeToGet = 0.045,
		multiplier = 2.3
	},
	[15] = {
		changeToGet = 0.04,
		multiplier = 2.4
	},
	[16] = {
		changeToGet = 0.035,
		multiplier = 2.5
	},
	[17] = {
		changeToGet = 0.03,
		multiplier = 2.6
	},
	[18] = {
		changeToGet = 0.025,
		multiplier = 2.7
	},
	[19] = {
		changeToGet = 0.02,
		multiplier = 2.8
	},
	[20] = {
		changeToGet = 0.018,
		multiplier = 2.9
	},
	[21] = {
		changeToGet = 0.016,
		multiplier = 3
	},
	[22] = {
		changeToGet = 0.014,
		multiplier = 3.1
	},
	[23] = {
		changeToGet = 0.012,
		multiplier = 3.2
	},
	[24] = {
		changeToGet = 0.01,
		multiplier = 3.3
	},
	[25] = {
		changeToGet = 0.009,
		multiplier = 3.4
	},
	[26] = {
		changeToGet = 0.008,
		multiplier = 3.5
	},
	[27] = {
		changeToGet = 0.007,
		multiplier = 3.6
	},
	[28] = {
		changeToGet = 0.006,
		multiplier = 3.7
	},
	[29] = {
		changeToGet = 0.0055,
		multiplier = 3.8
	},
	[30] = {
		changeToGet = 0.005,
		multiplier = 3.9
	},
	[31] = {
		changeToGet = 0.0045,
		multiplier = 4
	},
	[32] = {
		changeToGet = 0.004,
		multiplier = 4.1
	},
	[33] = {
		changeToGet = 0.0035,
		multiplier = 4.2
	},
	[34] = {
		changeToGet = 0.003,
		multiplier = 4.3
	},
	[35] = {
		changeToGet = 0.0025,
		multiplier = 4.4
	},
	[36] = {
		changeToGet = 0.002,
		multiplier = 4.5
	},
	[37] = {
		changeToGet = 0.0018,
		multiplier = 4.6
	},
	[38] = {
		changeToGet = 0.0016,
		multiplier = 4.7
	},
	[39] = {
		changeToGet = 0.0014,
		multiplier = 4.8
	},
	[40] = {
		changeToGet = 0.0012,
		multiplier = 4.9
	},
	[41] = {
		changeToGet = 0.001,
		multiplier = 5
	},
	[42] = {
		changeToGet = 0.0009,
		multiplier = 5.1
	},
	[43] = {
		changeToGet = 0.0008,
		multiplier = 5.2
	},
	[44] = {
		changeToGet = 0.0007,
		multiplier = 5.3
	},
	[45] = {
		changeToGet = 0.0006,
		multiplier = 5.4
	},
	[46] = {
		changeToGet = 0.0005,
		multiplier = 5.5
	},
	[47] = {
		changeToGet = 0.00045,
		multiplier = 5.6
	},
	[48] = {
		changeToGet = 0.0004,
		multiplier = 5.7
	},
	[49] = {
		changeToGet = 0.00035,
		multiplier = 5.8
	},
	[50] = {
		changeToGet = 0.0003,
		multiplier = 5.9
	},
	[51] = {
		changeToGet = 0.00025,
		multiplier = 6
	},
	[52] = {
		changeToGet = 0.0002,
		multiplier = 6.1
	},
	[53] = {
		changeToGet = 0.00018,
		multiplier = 6.2
	},
	[54] = {
		changeToGet = 0.00016,
		multiplier = 6.3
	},
	[55] = {
		changeToGet = 0.00014,
		multiplier = 6.4
	},
	[56] = {
		changeToGet = 0.00012,
		multiplier = 6.5
	},
	[57] = {
		changeToGet = 0.0001,
		multiplier = 6.6
	},
	[58] = {
		changeToGet = 0.00009,
		multiplier = 6.7
	},
	[59] = {
		changeToGet = 0.00008,
		multiplier = 6.8
	},
	[60] = {
		changeToGet = 0.00007,
		multiplier = 6.9
	},
	[61] = {
		changeToGet = 0.00006,
		multiplier = 7
	},
	[62] = {
		changeToGet = 0.00005,
		multiplier = 7.1
	},
	[63] = {
		changeToGet = 0.000045,
		multiplier = 7.2
	},
	[64] = {
		changeToGet = 0.00004,
		multiplier = 7.3
	},
	[65] = {
		changeToGet = 0.000035,
		multiplier = 7.4
	},
	[66] = {
		changeToGet = 0.00003,
		multiplier = 7.5
	},
	[67] = {
		changeToGet = 0.000025,
		multiplier = 7.6
	},
	[68] = {
		changeToGet = 0.00002,
		multiplier = 7.7
	},
	[69] = {
		changeToGet = 0.000015,
		multiplier = 7.8
	},
	[70] = {
		changeToGet = 0.00001,
		multiplier = 7.9
	}
}

local function determineNewLuck(currentLuck)
	for i = currentLuck + 1, #luckMultipliers do
		local chance = luckMultipliers[i].changeToGet
		if math.random() <= chance then
			return i
		end
	end
	return currentLuck
end

cloverEvent.OnServerEvent:Connect(function(plr)
	print("cloverEvent Fired!")
	local plrData = plr:WaitForChild("leaderstats")
	local plrLuck = plrData:WaitForChild("Luck")
	local plrMoney = plrData:WaitForChild("Money")
	if luckMultipliers[plrLuck] then
		local multiplier = luckMultipliers[plrLuck.Value].multiplier
		local moneyToAdd = 1 * multiplier
		local currentLuck = plrLuck.Value
		local newLuck = determineNewLuck(currentLuck)
		if newLuck > currentLuck then
			plrLuck.Value = newLuck
			print("Player " .. plr.Name .. " has obtained new luck level: " .. newLuck)
		else
			print("Player " .. plr.Name .. " did not obtain new luck.")
		end
	end
end)

why does it not working? pls help

Do you have any output? And try to explain the problem.

tell us more. like what is it supposed to do?

@Mihaqwest5 @batteryday


it should give the player luck 1 because luck 1 should have 1/1 change to get

You need to change this

To this

if luckMultipliers[plrLuck.Value] then

still not working it only print if the even fired

So what you have to do is debug

alright, do you think theres problem with the tables?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cloverEvent = ReplicatedStorage:WaitForChild("Clover")
local gameModule = require(ReplicatedStorage.ModuleScript)
local luckTables = gameModule.luckMultipliers

local function determineNewLuck(currentLuck)
	for i = currentLuck + 1, #luckTables do
		local chance = luckTables[i].changeToGet
		if math.random() <= chance then
			return i
		end
	end
	return currentLuck
end

cloverEvent.OnServerEvent:Connect(function(plr)
	print("cloverEvent Fired!")
	local plrData = plr:WaitForChild("leaderstats")
	local plrLuck = plrData:WaitForChild("Luck")
	local plrMoney = plrData:WaitForChild("Money")

	if luckTables[plrLuck.Value] then
		print("Found luck value")
		local multiplier = luckTables[plrLuck.Value].multiplier
		local currentLuck = plrLuck.Value
		local newLuck = determineNewLuck(currentLuck)

		if newLuck > currentLuck then
			print("Player " .. plr.Name .. " has obtained new luck level: " .. newLuck)
		else
			print("Player " .. plr.Name .. " did not obtain new luck.")
		end
	else
		print("Player " .. plr.Name .. " has an invalid Luck level, luck level: " ..plrLuck.Value)
	end
end)

I don’t know because I don’t fully understand it. I use weights when making a rarity system.

how i implement that with my current tables?

Math.random only returns 0 or 1, not a decimal.

local function determineNewLuck(currentLuck)
	for i = currentLuck + 1, #luckTables do
		local chance = luckTables[i].changeToGet
                local random = Random.new
		if random:NextInteger(0, 1) <= chance then
			return i
		end
	end
	return currentLuck
end

The new random should print a decimal
Lmk if that works

Sorry for the bad formatting, I’m typing this on my phone

i think there problem with tables, are table value can be named with number???

invalid player luck value, on the output

if table.find(luckTables, plrLuck.Value) then
		print("Found luck value")
		local multiplier = luckTables[plrLuck.Value].multiplier
		local currentLuck = plrLuck.Value
		local newLuck = determineNewLuck(currentLuck)

		if newLuck > currentLuck then
			print("Player " .. plr.Name .. " has obtained new luck level: " .. newLuck)
		else
			print("Player " .. plr.Name .. " did not obtain new luck.")
		end
	else
		print("Player " .. plr.Name .. " has an invalid Luck level, luck level: " ..plrLuck.Value)
	end

@batteryday @Pro3taco

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cloverEvent = ReplicatedStorage:WaitForChild("Clover")
local gameModule = require(ReplicatedStorage.ModuleScript)
local luckTables = gameModule.luckMultipliers

local random = Random.new()

local function determineNewLuck(currentLuck)
	for i = currentLuck + 1, #luckTables do
		local chance = luckTables[i].changeToGet
		if random:NextNumber() <= chance then
			return i
		end
	end
	return currentLuck
end

cloverEvent.OnServerEvent:Connect(function(plr)
	print("cloverEvent Fired!")
	local plrData = plr:WaitForChild("leaderstats")
	local plrLuck = plrData:WaitForChild("Luck")
	local plrMoney = plrData:WaitForChild("Money")

	if plrLuck.Value >= 0 and plrLuck.Value <= #luckTables then
		print("Found luck value")
		local currentLuck = plrLuck.Value
		local newLuck = determineNewLuck(currentLuck)

		if newLuck > currentLuck then
			print("Player " .. plr.Name .. " has obtained new luck level: " .. newLuck)
			plrLuck.Value = newLuck
		else
			print("Player " .. plr.Name .. " did not obtain new luck.")
		end
	else
		print("Player " .. plr.Name .. " has an invalid Luck level, luck level: " .. plrLuck.Value)
	end
end)

I found this working but why it jump from luck value 1 to luck value 4?? it does jump weirdly until it stuck at luck level 35