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

Something goes wrong when i try to use string.sub?

Asked by 6 years ago

Everytime i try to make a script like

local text = "blah blah blah"
for i = 1,#text do
    game.ReplicatedStorage:WaitForChild("StringValue").Value = string.sub(#text,1,i)
    wait()
end

the value only says a random number, such as "32","35","11", etc..

please help!

1 answer

Log in to vote
0
Answered by
D3LTA_Y 72
6 years ago
Edited 6 years ago

When you use "#", Lua reiceves a number, what when we are talking about a table or a string it means it's lenght, so you need to do the same thing whitout the "#" in string.sub's first argument, how like this:

--> made by Convexyz!

-- Variables --

str = "blah blah blah";

for i = 1, #str do

print(string.sub(str, 1, i));

end
0
got it @lunatic_o ! thank you :D xXAnimeIsRealLolXx 24 — 6y
0
No problem, marking the question as answered will be appreciated! D3LTA_Y 72 — 6y
Ad

Answer this question