Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Weight system prints everything in the table rather than one?

Asked by 3 years ago

I'm trying to make a gacha scroll system w/ weights, So I made a clickdetector inside a torso of a dummy, and placed a script inside it which you can see here:

local scrolltable = {
    ['Scroll1'] = 0.1,
    ['Scroll2'] = 0.1,
    ['Scroll3'] = 0.1,
    ['Scroll4'] = 2,
    ['Scroll5'] = 3,
    ['Scroll6'] = 4,
    ['Scroll7'] = 5,
    ['Scroll8'] = 5,
}

local Weight = 0

clickdetec.MouseClick:Connect(function(plr)
    for Scroll, Chance in pairs(scrolltable) do
        Weight += (Chance * 5)
        local ranNumber = math.random(1, Weight)
        if Weight >= ranNumber then
            print("Obtained ".. Scroll)
            else
            print("Not found?")
        end
    end
end)``

However, when I click on the torso it prints ALL of the scrolls and I only want it to choose one of them, how would I do this?

0
Update: I added a debounce to it which fixed the multiple scrolls issue, but now the weight straight up doesnt work. Instead it goes in order from bottom to top. kegirosou 17 — 3y
0
If you only want to choose one of them, add a 'break' after "print("Obtained ".. Scroll)" appxritixn 2235 — 3y

Answer this question