I need help with this, it keeps saying as an error http://prntscr.com/lfpm1n
Methods
are functions that belong to a specific object or table. When you call it, you use :
before the function's name. When you call a method, the first argument is automatically set. That argument is called, self
. For example, Destroy()
is a commonly used method. Clone()
as well. So many different types of instances have Destroy()
or Clone()
built in. When you call it, how does the script know which part to destroy since you aren't setting any arguments? Remember self
.
workspace.Part:Destroy() --This knows to destroy the part because the method can automatically obtain "self" workspace.Part.Destroy(workspace.Part) --When we call it like a normal function, we don't automatically get "self", so we need to define what we want to destroy ourselves.
Both the lines of code do the exact same thing.
String.match
contains 3 arguments. The first one is mandatory, the string you are looking for a match inside of. The second mandatory one is the string you want to find in the original one. The third, but optional, argument is an integer (or number) which tells the function what point they should start searching from. The third argument must be a number always.
local string = "My favorite color is blue or pink" print(string.match(string, "o", 28))
nil
Here is your code:
local Tplayer = game.Players:FindFirstChild(msg:match(v.Name, msg:sub(6)))
You are calling string.match
as a method. Calling it as a method is perfectly fine! In this case, however, not so much. What you are actually doing is trying to find v.Name
inside of msg
starting from the msg:sub(6)
th letter... The third argument must always be a number. It makes no sense to the script, so it throws an error. The simple solution is to not use it like a method in this case.
local Tplayer = game.Players:FindFirstChild(string.match(v.Name, msg:sub(6)))
Hope it helps!