#"getRandomIndex is not a valid member of ModuleScript"

1 messages · Page 1 of 1 (latest)

chrome kite
#

My code isn't working, it says that "getRandomIndex is not a valic member of ModuleScript "ServerScriptService.Main.SelectChance"". Can anyone help me with this?

Main:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remotes = replicatedStorage:WaitForChild("Remotes")

local selectChance = script:WaitForChild("SelectChance")
local chanceList = script:WaitForChild("ChanceList")

remotes:WaitForChild("RollFunction").OnServerInvoke = function(player)
    local Table = {}
    
    for i = 1, 7 do
        
        table.insert(Table, selectChance.getRandomIndex(chanceList))
    end
    
    return Table
end

SelectChance:

return {
    getRandomIndex = function(chances)
        for i, v in ipairs(chances) do
            local randomNum = math.random(1, v[2])
            if randomNum == 1 and v[2] > chances[1][2] then
                return {
                    v[1];
                    v[2];
                    v[3];
                }
            end
        end
        
        return chances[1]
    end,
}
unique elbow
#

You forgot to require it

worn ingot
#

yes

#

local selectChance = require(script.SelectChance)

#

also watch crusherfire's video on this, its worth the time https://www.youtube.com/watch?v=7tzy1DuPcBQ

WaitForChild() is misused all the time, and I'm guilty of it too. Hopefully, this video will shed some light on when and when NOT to use WaitForChild()!

Have you ever wanted to learn Roblox Studio and Roblox Scripting? Check out my course: https://bit.ly/LuaScriptingCourse
Use code DEVELOPERS for 33% off!

My linktree:
https://linktr.ee/crusher...

▶ Play video
dusk gyro
#

@chrome kite local selectChance = require(script.SelectChance)