Greetings. I’m currently working on an admin script that catches arguments sent by a player through chat in order to execute the commands.
For some reason, when it grabs arguments using a table.split() which turns the message into a table where arguments can be removed using table.remove()
I’m having a problem with the function that looks for players. Quick Note: This was not happening before and started happening out of the blue. It has happened before but it auto fixed itself as well. Just wanted to know if anyone was also having this problem.
The solution I found to get the exact argument, without the extra space at the end, would be to use a string.sub() on the string and tell it to read itself except for the last argument.
local function FindPlayer(name)
local name = string.gsub(name, " ", "")
if string.sub(name, 1, string.len(name) - 1) == "me" then return player end
if (name ~= nil or name ~= '') then
if name ~= string.sub(name, 1, string.len(name) - 1) then
local length = string.len(name)
for i,v in pairs(game.Players:GetPlayers()) do
if string.sub(v.Name, 1, length - 1):lower() == string.sub(name, 1, length - 1):lower() then
return v
end
Even when I try to do (Let’s say I typed ;kill me):
print(name == "me")
It would return as false since it’s actually "me " for some reason.
EDIT: Yes, I’m aware I’m returning the player’s instance and not name.