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

Is this an effective way of creating a random box?

Asked by 5 years ago

Here is the script:

    local ranGen = Random.new(tick())
    local lSPC = 1
    local rSPC = 2
    local uSPC = 100
    local oSPC = 350

    local function randomBoxChooser()

        local ranNum = ranGen:NextInteger(1, 1000)
        print(ranNum)
        if ranNum >= oSPC then

            return "Ordinary Box"

        elseif ranNum >= uSPC then

            return "Uncommon Box"

        elseif ranNum >= rSPC then      

            return "Rare Box"

        elseif ranNum >= lSPC then

            return "Legendary Box"

        end

    end

I originally had a for loop going up to a thousand and putting in names of the boxes based on probability but that seemed really inefficient to me so I changed it. Just wanted to know if this was the most efficient way. Also later on I Clone the box into workspace at a random CFrame. Now I have read an article on how we should set the parent last and was wondering if that applied to CFrame as well. Here is an example of what I mean:

local box = serverBox:Clone()
box.Parent = game.Workspace
box.CFrame = location

Hope you guys can help. Thanks!

0
It's not a bad system, but there is one flaw, you are checking if each number is greater than the number you specified, on line 11 you're saying if the number is greater than 1 it will return "Ordinary Box" which will always be true since your indexing a number 1-1000. So you should do "if ranNum >= oSPC and ranNum < uSPC" and so forth. YabaDabaD0O 505 — 5y
0
No I am not. You must not have read my code very carefully. User#21908 42 — 5y
0
oSPC = 350 User#21908 42 — 5y
0
on line five User#21908 42 — 5y

Answer this question