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

Im trying to make a rarity thing and i dont know if this is the right way to do it or not. Help?

Asked by 8 years ago

Let me explain better. I want to make a script like the one in the quarry. its a script that for every block in a model, it takes a random part from The list (Blocks) and puts it into that parts position under the parent field. all I need is a way to create a rarity thing without doing this:

Blocks=     {"Emerald","Emerald","Ruby","Sapphire","Diamond","Ruby","Sapphire","Coal","Coal","Coal","   Coal","Coal","Coal","Coal","Gold","Gold","Gold","Gold","Gold","Dirt","Dirt","Dirt","Dirt","Dirt",   "Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","  Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","D  irt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dir t","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt  ","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt", "Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","  Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Dirt","Stone","Stone","Stone","Stone",   "Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","S  tone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Sto  ne","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone  ","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone"," Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","Stone","St  one","Stone","Stone","Stone","Stone","Stone","Sand","Sand","Sand","Sand","Sand","Sand","    Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sa  nd","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand  ","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand"," Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sand","Sa  nd","Sand","Sand","Sand","Sand","Sand","Sand","Sand"}

function MineSweeper()
    if script.Parent.Parent.Generate.Running.Value == true then
    script.Parent.Parent.Field:ClearAllChildren()
    if script.Parent.Parent.Generate.Running.Value == true then
    for _, Part in pairs(script.Parent:GetChildren()) do
  local Rocky = game.Lighting:FindFirstChild(Blocks[math.random(1,#Blocks)])
    local Mine = Rocky:Clone()
        Mine.Position = Part.Position
        Mine.Parent = script.Parent.Parent.Field
end
end
end
end
script.Parent.Parent.Generate.ClickDetector.MouseClick:connect(MineSweeper)

Before you answer, I don't think dictionaries will help.

1 answer

Log in to vote
0
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

I see what you are trying to do. A more efficient way is a chance function.

What I did is created a function that picks a random block and returns it to your main function. It chooses a block at random with chances. You can add more blocks to the function and if you want the chances for rarer rocks to be lower, raise the scope on the roll.

local function DecideBlock()
    local Roll = math.random(1,100)
    local Block = "Dirt"
    if Roll <= 49 then
        Block = "Dirt"
    elseif Roll > 50 and Roll <= 74 then
        Block = "Sand"
    elseif Roll > 75 and Roll <= 100 then
        Block = "Stone"
    end
    return Block
end

function MineSweeper()
    if script.Parent.Parent.Generate.Running.Value == true then
    script.Parent.Parent.Field:ClearAllChildren()
    if script.Parent.Parent.Generate.Running.Value == true then
    for _, Part in pairs(script.Parent:GetChildren()) do
  local Rocky = game.Lighting:FindFirstChild(DecideBlock())
    local Mine = Rocky:Clone()
        Mine.Position = Part.Position
        Mine.Parent = script.Parent.Parent.Field
end
end
end
end
script.Parent.Parent.Generate.ClickDetector.MouseClick:connect(MineSweeper)
Ad

Answer this question