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

Can anyone explain to me what :sub() and :len() does ?

Asked by 6 years ago

so like here just a script can anyone explain to me what the :sub() part does. This is just a map changing script. I just don't understand what it does. same with :len()

01-- Store all your maps in Lighting.
02 
03current_map = nil
04 
05names = {}
06 
07game.Players.PlayerAdded:connect(function(player)
08    for i, v in pairs(names) do
09        if v == player.Name then
10            player.Chatted:connect(function(chatmsg)
11                if chatmsg:sub(1,4) == "map/" then
12                    local map = chatmsg:sub(5, chatmsg:len())
13                    if game.Lighting:FindFirstChild(map) then
14                        if current_map ~= nil then
15                            current_map.Parent = game.Lighting
View all 24 lines...
1
len is how long it is and sub is the character in binary between two points kingleonlion 2 — 6y
0
instead of len you can also use #StringVariable or #("String") RubenKan 3615 — 6y

1 answer

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

sub() parses a subsection of the provided string.

1local foo = "Abcdef"
2print(foo:sub(1,4)) --> Abcd

len() returns the length of the provided string.

1local foo = "Abcdef"
2print(foo:len()) --> 6

What it seems to do in the instance you have provided above is parse the string from the fifth character to the last character (the message's length). len() actually doesn't need to be used here at all because the second parameter of sub() is optional, and when not provided will automatically parse from the first argument to the end of the string.

0
ty WillBe_Stoped 71 — 6y
Ad

Answer this question