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

How can I pick items out of a table, out of a table, randomly with different precents?

Asked by 3 years ago
Edited 3 years ago

Here is my code

--Defining Races--
finalizedrace = script.Parent.FinalizedRace
baserace = script.Parent.Race
HumanRaces = {"Ashura", "Rony", "Choni", "Loreli", "Bolero"}
BirdRaces = {"Squaker", "Cardins", "Rito", "Zoluno", "Phoenix"}
FishRaces = {"FH1", "FH2", "FH2", "FH4", "FH5"}
MythicalRaces = {"MH1", "MH2", "MH3", "MH4", "MH5"}
baserace = {"HumanRaces", "BirdRaces", "FishRaces", "MythicalRaces"}
-------------------------------------------------------------------- < All Dis Stuff Above Is Race Tables

if script.Parent.AlreadyHasRace.Value == false then
local BaseRaceChosen = math.random(1, #baserace)
wait(2)
print(baserace[BaseRaceChosen],"Has been chosen.")


baserace.Value = baserace[BaseRaceChosen]

print(baserace.Value, "Has been set to the value of base races.")
if baserace.Value == "HumanRaces" then
-----------------Human Race Gen---------------------------------
local FinalizeRaceHuman = math.random(1, #HumanRaces)
    wait(2)
print(HumanRaces[FinalizeRaceHuman],"Finalized Race Generated.")
finalizedrace.Value = HumanRaces[FinalizeRaceHuman]
    print(finalizedrace.Value, "Finalized Values Generated.")
-----------------Bird Race Gen----------------------------------
    elseif baserace.Value == "BirdRaces" then
local FinalizeRaceBird = math.random(1, #BirdRaces)
    wait(2)
print(BirdRaces[FinalizeRaceBird],"Finalized Race Generated.")
finalizedrace.Value = BirdRaces[FinalizeRaceBird]
    print(finalizedrace.Value, "Finalized Values Generated.")
----------------Fish Race Gen------------------------------------
    elseif baserace.Value == "FishRaces" then
local FinalizedRaceFish = math.random(1, #FishRaces)
    wait(2)
print(FishRaces[FinalizedRaceFish],"Finalized Race Generated.")
finalizedrace.Value = FishRaces[FinalizedRaceFish]
    print(finalizedrace.Value, "Finalized Values Generated.")
----------------Mythical Race Gen--------------------------------
    elseif baserace.Value == "MythicalRaces" then
local FinalizeRaceMythical = math.random(1, #MythicalRaces)
    wait(2)
print(MythicalRaces[FinalizeRaceMythical],"Finalized Race Generated.")
finalizedrace.Value = MythicalRaces[FinalizeRaceMythical]
    print(finalizedrace.Value, "Finalized Values Generated.")
------------------------------------------------------------------
       script.Parent.AlreadyHasRace.Value = true        
    end 
end

At the human gen bird gen fish gen and mythical gen i just took the script from my base race generator. What I did was took 4 tables with string values, put each of the tables in a table, roll a table randomly with even chances, and now I'm trying to roll each of the races unevenely. Like say I want Ashura to have 20% chance and Loreli 10%. How would I do that? Thank you.

0
I have some old code that was supposed to do something like this. Mind if I post it as an answer? User#30567 0 — 3y
0
Sure you can do it JazzyLOLLOL123 0 — 3y

Answer this question