Rarity system not working and buggy pls help

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cloverEvent = ReplicatedStorage:WaitForChild("Clover")
local gameModule = require(ReplicatedStorage:WaitForChild("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 want it like a level system but its luck level, only if player is lucky enough so they can level up

why does it it jump from luck level 1 to luck level 4 and it does that until luck level 70, also the luck are not realistic, it always level up even it skip the level, pls help

1 Like

I believe its going from 1 to 4 luck because its not interating the lucktable you have in order. For Ex
Example = {
[“One”]
[“Three”]
[“Two”]
}
You have to code a iteration that put the numbers in order from lowest level to highest in your table then connect your table to that iteration.

Also you have “random:nextnumber” in your script maybe its picking a random next number which is why its going from 1 to 4.

1 Like