I want to use math.random, but i'm not sure how or if it will work. Here is the script:
wait(2) if script.Parent.Visible == true then script.Parent.Text = script.Parent.Fact1.Value wait(6) script.Parent.Text = script.Parent.Fact2.Value wait(6) script.Parent.Text = script.Parent.Tip1.Value end
Maybe, if you think like the most beginners, you will think on a script like this
local rand = math.random(1,3) -- draw a number between 1 and 3 wait(2) if script.Parent.Visible == true then if rand == 1 then script.Parent.Text = script.Parent.Fact1.Value wait(6) elseif rand == 2 then script.Parent.Text = script.Parent.Fact2.Value wait(6) elseif rand == 3 then script.Parent.Text = script.Parent.Tip1.Value wait(6) end end
Obvoiusly, this is too long. Maybe you should use a table
. You can consider it as a value container:
local myFirstTable = {nil, false, "dav1000999", 563754, math.huge, nil, "efl"}
So, you can use it to shorten your script. Once the three results use the same structure, we can replace them.
local values = {"Fact1", "Fact2", "Tip1"} -- gets the names local num = math.random (1,3) -- draws a number if script.Parent.Visible == true then script.Parent.Text = script.Parent:WaitForChild(values[num]).Value -- takes the name in basis of the number wait(6) end
Hope it helps!