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 5 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

01adjective1 = script.Parent.Parent.Base.youare.Adjectives.Frame.chaotic
02adjective2 = script.Parent.Parent.Base.youare.Adjectives.Frame.fancy
03adjective3 = script.Parent.Parent.Base.youare.Adjectives.Frame.fierce
04adjective4 = script.Parent.Parent.Base.youare.Adjectives.Frame.majestic
05adjective5 = script.Parent.Parent.Base.youare.Adjectives.Frame.powerful
06adjective6 = script.Parent.Parent.Base.youare.Adjectives.Frame.stunning
07adjective7 = script.Parent.Parent.Base.youare.Adjectives.Frame.unique
08adjective8 = script.Parent.Parent.Base.youare.Adjectives.Frame.wholesome
09 
10noun1 = script.Parent.Parent.Base.youare.Nouns.Frame.cat
11noun2 = script.Parent.Parent.Base.youare.Nouns.Frame.eagle
12noun3 = script.Parent.Parent.Base.youare.Nouns.Frame.flower
13noun4 = script.Parent.Parent.Base.youare.Nouns.Frame.human
14noun5 = script.Parent.Parent.Base.youare.Nouns.Frame.lion
15noun6 = script.Parent.Parent.Base.youare.Nouns.Frame.mountian
16noun7 = script.Parent.Parent.Base.youare.Nouns.Frame.potato
17noun8 = 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.

01script.Parent.MouseButton1Click:Connect(function()
02    local adjective = math.random(1,8)
03    local noun = math.random(1,8)
04 
05    if adjective == 1 then
06        adjective1.TextColor3 = Color3.new(255,255,255)
07        adjective1.TextStrokeColor3 = Color3.new(255,255,255)
08 
09        or adjective == 2 do
10            adjective2.TextColor3 = Color3.new(255,255,255)
11            adjective2.TextStrokeColor3 = Color3.new(255,255,255)
12        end
13    end
14end)

1 answer

Log in to vote
4
Answered by 5 years ago

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

01local adjectives = {
02script.Parent.Parent.Base.youare.Adjectives.Frame.chaotic,
03script.Parent.Parent.Base.youare.Adjectives.Frame.fancy,
04script.Parent.Parent.Base.youare.Adjectives.Frame.fierce,
05script.Parent.Parent.Base.youare.Adjectives.Frame.majestic,
06script.Parent.Parent.Base.youare.Adjectives.Frame.powerful,
07script.Parent.Parent.Base.youare.Adjectives.Frame.stunning,
08script.Parent.Parent.Base.youare.Adjectives.Frame.unique,
09script.Parent.Parent.Base.youare.Adjectives.Frame.wholesome
10}

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

01local adjectives = {
02script.Parent.Parent.Base.youare.Adjectives.Frame.chaotic,
03script.Parent.Parent.Base.youare.Adjectives.Frame.fancy,
04script.Parent.Parent.Base.youare.Adjectives.Frame.fierce,
05script.Parent.Parent.Base.youare.Adjectives.Frame.majestic,
06script.Parent.Parent.Base.youare.Adjectives.Frame.powerful,
07script.Parent.Parent.Base.youare.Adjectives.Frame.stunning,
08script.Parent.Parent.Base.youare.Adjectives.Frame.unique,
09script.Parent.Parent.Base.youare.Adjectives.Frame.wholesome
10}
11 
12local 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 — 5y
0
if i did that i dont think i could make the vars and choose Donald_TrumpREAL1238 -27 — 5y
Ad

Answer this question