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

How to make a math.random choose between a different variable?

Asked by 4 years ago

So I want this poster to change words. There are 8 adjectives and 8 nouns. Each variable before the mousebutton1click function starts looks like this

adjective1 = script.Parent.Parent.Base.youare.Adjectives.Frame.chaotic
adjective2 = script.Parent.Parent.Base.youare.Adjectives.Frame.fancy
adjective3 = script.Parent.Parent.Base.youare.Adjectives.Frame.fierce
adjective4 = script.Parent.Parent.Base.youare.Adjectives.Frame.majestic
adjective5 = script.Parent.Parent.Base.youare.Adjectives.Frame.powerful
adjective6 = script.Parent.Parent.Base.youare.Adjectives.Frame.stunning
adjective7 = script.Parent.Parent.Base.youare.Adjectives.Frame.unique
adjective8 = script.Parent.Parent.Base.youare.Adjectives.Frame.wholesome

noun1 = script.Parent.Parent.Base.youare.Nouns.Frame.cat
noun2 = script.Parent.Parent.Base.youare.Nouns.Frame.eagle
noun3 = script.Parent.Parent.Base.youare.Nouns.Frame.flower
noun4 = script.Parent.Parent.Base.youare.Nouns.Frame.human
noun5 = script.Parent.Parent.Base.youare.Nouns.Frame.lion
noun6 = script.Parent.Parent.Base.youare.Nouns.Frame.mountian
noun7 = script.Parent.Parent.Base.youare.Nouns.Frame.potato
noun8 = script.Parent.Parent.Base.youare.Nouns.Frame.tree

Now I could have made a table, but i didnt feel like it. Now when you do math.random it would choose a number 1,8. The number it gets would be one adjective, and I would make another variable in the function and it would give me one noun. I have not completed the script but please tell me how i would do this.

script.Parent.MouseButton1Click:Connect(function()
    local adjective = math.random(1,8)
    local noun = math.random(1,8)

    if adjective == 1 then
        adjective1.TextColor3 = Color3.new(255,255,255)
        adjective1.TextStrokeColor3 = Color3.new(255,255,255)

        or adjective == 2 do
            adjective2.TextColor3 = Color3.new(255,255,255)
            adjective2.TextStrokeColor3 = Color3.new(255,255,255)
        end
    end
end)

1 answer

Log in to vote
4
Answered by 4 years ago

Its much, much better practice to just put these in a table. It would make it a lot more simple.

local adjectives = { 
script.Parent.Parent.Base.youare.Adjectives.Frame.chaotic,
script.Parent.Parent.Base.youare.Adjectives.Frame.fancy,
script.Parent.Parent.Base.youare.Adjectives.Frame.fierce,
script.Parent.Parent.Base.youare.Adjectives.Frame.majestic,
script.Parent.Parent.Base.youare.Adjectives.Frame.powerful,
script.Parent.Parent.Base.youare.Adjectives.Frame.stunning,
script.Parent.Parent.Base.youare.Adjectives.Frame.unique,
script.Parent.Parent.Base.youare.Adjectives.Frame.wholesome
}

And do the same for the other. Now that thats in order, we can pick a random result:

local adjectives = { 
script.Parent.Parent.Base.youare.Adjectives.Frame.chaotic,
script.Parent.Parent.Base.youare.Adjectives.Frame.fancy,
script.Parent.Parent.Base.youare.Adjectives.Frame.fierce,
script.Parent.Parent.Base.youare.Adjectives.Frame.majestic,
script.Parent.Parent.Base.youare.Adjectives.Frame.powerful,
script.Parent.Parent.Base.youare.Adjectives.Frame.stunning,
script.Parent.Parent.Base.youare.Adjectives.Frame.unique,
script.Parent.Parent.Base.youare.Adjectives.Frame.wholesome
}

local result = adjectives[math.Random(1,#adjectives)]
0
for this wouldent it be easier just to do "script.Parent.Parent.Base.youare.Adjectives.Frame:GetChildren" since they are all children of the frame? Benbebop 1049 — 4y
0
if i did that i dont think i could make the vars and choose Donald_TrumpREAL1238 -27 — 4y
Ad

Answer this question