Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

bad argument #1 to 'sub' (string expected, got function)?

function text(txt)
    for i = 1, #txt do
	    script.Parent.Text.Text = string.sub(text, 1, i)
	    wait()
    end
end

text("yo gang")

I know whats wrong I just don't know a good way of fixing it

1 answer

You are putting the function "text" under the parameters of string.sub. To fix this, simply change the parameters to "txt" instead.

Also, to get the length of a text, I believe you must do string.len(txt) rather than #txt, for "#" returns the number of values inside a table.

Thus, the code should look like this:

local function text(txt)
    for i = 1, string.len(txt) do
	    script.Parent.Text.Text = string.sub(txt, 1, i)
	    wait()
	end
end

text("yo gang")

Hope this helps! Message me with any problems you may have :)

2 comments

1

You are absolutely wrong. The length operator works for strings as well. It returns the length of the string.

0

Okay, well that’s easily fixable. Did this fix your function though?

This discussion is preserved as it was. New answers, comments, and votes are closed.