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

Can anyone explain how :sub() works or link me to some place that explains?

im having a hard time with my teleportation system because i need to use :sub() for it to work but idk how :sub() works, can someone pls explain here is a line of a script to better explain

if game.Players:FindFirstChild(msg:sub(6)) then

how does the :sub() work?

3 comments

0

What do you mean by sub()? Is it string.sub() or something else? Also if you have a code, please put it on your question.

0

here is code

1

What it does is if msg == "Hi there people", msg:sub() would return "ere people", because like RobloxWhiz said, it returns a substring from the start number (6 in your case)to the end number, (end of string in your case, because you din't assign one)

2 answers

sub(start, end) is the shorter version of string.sub(). It returns the part of the string from start to end. If you only give it start, the end parameter will automatically be assigned to #string.

Example of using sub():

local string = "Hello World"
local subbed_string = string:sub(7) -- Returns "World"
print(subbed_string) -- "World"

The above example uses only the first parameter to extract a part of the string. The second parameter automatically gets the #string argument, which is why it returned World.

1 comment

1

yeah, @RobloxWhizYT is correct

If you mean the string.sub function, then it is a function that returns the substring of the given string. For example,

print(string.sub("abcde", 2, 4))

would print

"bcd"

(Or at least that's how it remember it)

If you want more information, i suggest looking here: http://lua-users.org/wiki/StringLibraryTutorial

1 comment

0

look at the code above

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