Since I dont use Lua I get into these problems alot and I am looking for some help. I am making this dialog system where a list of string is given as parameter and i want to loop throught the list and the string but I get the error "attempt to get length of a number value ".
I would appriciate it if someone helped me with this problem
function Dialog.Type(TextList: "list of strings", Speed: "number", Pause: "number")
local Gui = Dialog.Get_GUI()
local TextLabel = Gui:FindFirstChild("TextBox")
for Text = 1, #TextList do
for Letter = 1, #Text, 1 do
TextLabel.Text = string.sub(Text,1,Letter)
wait(Speed)
end
if Pause then
wait(Pause)
end
end
end
return Dialog
You were trying to get the length of Text, which on your first for loop is a number.
Try this:
function Dialog.Type(TextList: "list of strings", Speed: "number", Pause: "number")
local Gui = Dialog.Get_GUI()
local TextLabel = Gui:FindFirstChild("TextBox")
for Text = 1, #TextList do
for Letter = 1, string.len(TextList[Text]), 1 do
TextLabel.Text = string.sub(TextList[Text],1,Letter)
wait(Speed)
end
if Pause then
wait(Pause)
end
end
end
return Dialog
If TextList is an array then you are using #TextList correctly on the first for loop, but for the second for loop, why are you trying to get the length of #Text which is a number value of the for loop?
The thing is, the Text is the index, not the value, so your looping the table with an index not a value, so you would have to change it to use I,v in pairs() or find the value using the index, heres an example:
function Dialog.Type(TextList, Speed, Pause)
local Gui = Dialog.Get_GUI()
local TextLabel = Gui:FindFirstChild("TextBox")
for i = 1, #TextList do
local Text = TextList[i]
for Letter = 1, #Text do
TextLabel.Text = string.sub(Text, 1, Letter)
wait(Speed)
end
if Pause then
wait(Pause)
end
end
return Dialog
end
I am used to using python and this was the first time that came to me when looking up for a tutorial. But i see where you are coming from and thanks for that.