I think you didn’t understood, texts is a dictionary, not an array, things like # do not work with dictionaries. I tried your code, nothing prints out because #texts is 0.
local texts = {
Text1 = 1,
Text2 = 2,
Text3 = 3,
Text4 = 4
}
local n = 0
for i, v in pairs(texts) do
n += 1
end
for i = 1, n do
print(texts["Text"..i])
end
You should use either for i = 1, #texts or for i,text in ipairs(texts) do
using in pairs does them in a random order I believe.
ipairs is like the for i version of pairs
Also it’s a dictionary. They are ordered as only string values currently
--You need to either do --
local texts = {Text1 = 1, Text2 = 2,Text3 = 3,Text4 = 4}
--this orders them correctly--
--You can also do--
local texts = {}
texts[1] = 1
texts[2] = 2
texts[3] = 3
texts[4] = 4
The first loop is useless, you can just do this for it:
local n = 0
local texts = {
Text1 = 1,
Text2 = 2,
Text3 = 3,
Text4 = 4
}
task.spawn(function()
repeat
n += 1
until n == 4
end)
for i = 1, n do
print(texts['Text: ']..i)
end
Ok so not to come off rude, but please do at least attempt one of our samples. You won’t get anywhere telling us what was said in the post, instead of telling us what isn’t working from our code.
ipairs is meant for arrays, hence me using one in this fashion:
local texts = {Text1 = "sample text", Text2 = "sample text2", Text3 = "sample text3"}
for k, v in ipairs(texts) do
print(tostring(k))
task.wait(2)
end
I will be further discontinuing my replies to this thread, I wish you the best of luck.