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

How come my Scrolling-Text code is not scrolling/entering strings correctly?

What is the problem?

The problem is that it is not scrolling a specific piece of Text (a sequence of a String), but instead keeps doing something else than what it is supposed to do, and sometimes skips a line; However, I have indicated where the problem is.

Was there any Output?

Sadly, I can not provide any, as it is not giving any errors, however, I have added print functions for specific parts of the code, but they are not printing correctly either (it's not doing specific lines that the code is supposed to do, and sometimes skips a line).

What is the code? Can you provide it?

Yes, I can provide the code, however, it is very confusing, and I have done a lot of changes to try and get it to work finally, but all attempts resulted in the same thing. Here is the code:

local sl = {1}; local ll = {};
local msg = "I'm|a|string!|:D"

for q = 1, #msg do
	if msg:sub(q,q) == "|" then
		table.insert(sl,q + 1)
		table.insert(ll,q - 1)
	end
end

if #sl == 0 then
	table.insert(sl,msg)
else
	for x = 1, #sl do
		if sl[x] and ll[x] then
			print(sl[x],ll[x],msg:sub(sl[x],ll[x]))
		elseif sl[x] and not ll[x] then
			print(sl[x],msg:sub(sl[x]))
		end
	end
end

print("Start Scroll")
for x = 1, #sl do --The problem is in this chunk somewhere I'm guessing
	local CurMes = sl[x] and ll[x] and msg:sub(sl[x],ll[x]) or sl[x] and msg:sub(sl[x])
	for k = 1, #CurMes do
		if sl[x] and ll[x] and CurMes:sub(sl[x],ll[x]) ~= "" then
			print(CurMes:sub(1,k))
		elseif sl[x] and CurMes:sub(sl[x]) ~= "" then
			print(CurMes:sub(1,k))
		end
		wait(1/25)
	end
	wait(2.5)
end
print("Finished scroll")

2 comments

0

What exactly are you trying to do? I have a gut feeling that you're overcomplicating something easy.

0

Well, the script is supposed to take apart the String when the first 'for' loop reaches every '|' in the string, then returns the first, and end position into 'sl', and 'll' (the tables), then after so, proceeds to attempt to right out the separated strings (starting at line 24).

1 answer

✓ Accepted answer
message = "|I'm|a|string!|:D"
words = {}

--[[ string.gsub replaces stuff with other stuff in
	strings. Here, it's replacing those thingamajigs
	with the NULL character, \0. If you actually try
	printing out the NULL character, you won't see
	anything; it's like nil, as a character.
--]]

message = message:gsub("|", "\0")

counter = 1

--[[ string.gmatch will find every instance of the
	thing that you give it in the message. I recommend
	looking up "roblox string patterns" and
	educating yourself on that. Basically, we are matching
	anything that is not the NULL character, and adding
	that to the array of words.
--]]

for word in message:gmatch("%Z+") do
	words[counter] = word
	counter = counter + 1
end

for _, word in pairs(words) do
	for i = 1, #word do
		print(word:sub(1, i))
	end
end

1 comment

1

Thanks a lot man! :D I heard about 'String Patterns', but I couldn't remember the name of the code type. :P I'll try and learn it along the way. :) Thanks for helping me out!

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