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

math.random Textlabels in gui?

Asked by 9 years ago

I tryed to make an script that shows random textlabel in the gui, (On screen) The tb1-9 are the names of the textlabel but not the text. I need to have them random ordering on the screen. Sorry my English. I hope someone can help me. Thanks.

while wait (2) do math.random(1)
script.Parent.tb1.Visible = true
wait (60)
script.Parent.tb1.Visible = false
wait ()
script.Parent.tb2.Visible = true
wait (60)
script.Parent.tb2.Visible = false
wait ()
script.Parent.tb3.Visible = true
wait (60)
script.Parent.tb3.Visible = false
wait ()
script.Parent.tb4.Visible = true
wait (60)
script.Parent.tb4.Visible = false
wait ()
script.Parent.tb5.Visible = true
wait (60)
script.Parent.tb5.Visible = false
wait ()
script.Parent.tb6.Visible = true
wait (60)
script.Parent.tb6.Visible = false
wait ()
script.Parent.tb7.Visible = true
wait (60)
script.Parent.tb7.Visible = false
wait ()
script.Parent.tb8.Visible = true
wait (60)
script.Parent.tb8.Visible = false
wait ()
script.Parent.tb9.Visible = true
wait (60)
script.Parent.tb9.Visible = false
wait ()
end

2 answers

Log in to vote
1
Answered by 9 years ago

Try this:

local GUI = script.Parent --This is setting the script.Parent to a variable for later access
local Names = {"tb1", "tb2", "tb3", "tb4", "tb5", "tb6", "tb7", "tb8", "tb9"} --This is a table of the names of all the labels that you want to make visible/invisible
while true do --Infinite loop
    local ChosenName = Names[math.random(1, #Names)] --This uses the math.random() function to get a random element from table "Names"
    local ChosenLabel = GUI:FindFirstChild(ChosenName) --This checks to see if the chosen name is a child of the GUI
    if ChosenLabel then --If the ChosenLabel exists...
        ChosenLabel.Visible = true --Make the label visible
        wait(60) --Wait 1 minute
        ChosenLabel.Visible = false --Make the label invisible
    end
    wait() --This wait is here and not in the conditional to prevent the loop from crashing if the ChosenLabel doesn't exist
end

Hope this helped!

Ad
Log in to vote
-1
Answered by 9 years ago

You need to have another variable for the table

local TextLabel = script.Parent.Name
local listOfPhrases = {"tb1","tb2","tb3","tb4","tb5","tb6","tb7","tb8","tb9"} 

while wait() do
    TextLabel.Name = Table[math.random(1, #Table )] 
end

Answer this question