I've written the following code to continuously loop sting values, repeating in the same order infinitely. I was just curious if there was any way to write lines 6 through 13 more effectively?
local message = script.Parent local myArray = {"Hello, there.", "General Kenobi!", "I am the Senate.", "Not... yet."} while true do message.Name = myArray[1] wait(3) message.Name = myArray[2] wait(3) message.Name = myArray[3] wait(3) message.Name = myArray[4] wait(3) end
you could try to do a for loop:
local message = script.Parent local myArray = {"Hello, there.", "General Kenobi!", "I am the Senate.", "Not... yet."} while true do for i = 1, #myArray do message.Name = myArray[i] wait(3) end end
in my opinion, for loops work better for longer tables, also you could do
local message = script.Parent local myArray = {"Hello, there.", "General Kenobi!", "I am the Senate.", "Not... yet."} while true do for _,v in pairs(myArray) do message.Name = v wait(3) end end
the latter also works for dictionaries