So, for a command, I've got it set to run a function to find the player:
local plyr = getPlayer(message:sub(7))
And heres the function:
function getPlayer(str) local plyr = {} str = str:lower() local l = string:len(str) for i,v in pairs(game.Players:children()) do if v:IsA("Player") then if v.Name:sub(1, l) == str then plyr = v end end end end
But I get the error: calling 'len' on bad self (string expected, got table)
What the script thinks you're doing is running a function on the keyword string. When you try calling a function in a table with ":" the script will assume you're calling the function with the table itself being the first argument. That's why you may see
tab = { i = 'Hello'; p = function(self) print(self.i) end } tab:p()
Or method similar to this. The script should end up printing the i variable. What "string" is, is basically an array of functions that is a keyword for all scripts.
You can go two ways.
StringOrStringVariableHere:len()
function on the actual string itself.string.len(StringOrStringVariableHere)
function getPlayer(str) local plyr = {} str = str:lower() local l = string.len(str) for i,v in pairs(game.Players:children()) do if v:IsA("Player") then if v.Name:sub(1, l) == str then plyr = v end end end end