Since I realize that this may be a bit vague for the question, here is probably a more elaborate description of my problem. As of right now, I'm trying to make it so that when a player is targeted in chat, you don't have to completely fill out there name (ie. To target me, you say I or IXL).
So far I have this (doing this on mobile so pardon my tabs; I know how to correctly tab my scripts):
function findTargets(caller, target) local marks = {} for i, v in pairs(game.Players:GetPlayers) do if string.lower(target) == string.lower(v) then table.insert(marks, v) end end return marks end
However, it takes my entire name in order for me to be targeted. Anyway how to fix it?
I suppose you're making an admin script.
function findTargets(caller, message) local allPlayers = game.Players:GetPlayers() -- get the players local foundPlayers = {} -- empty table (for now) message = message:lower() -- convert the message to a lowercase form local messageLength = #message -- length of message for _, player in pairs( allPlayers ) do -- go through all the players local name = player.Name:lower() -- get the name, in a lowercase form if name:sub( 1, messageLength ) == message then -- if the part of the name is the same as the message table.insert( foundPlayers, player ) end end return foundPlayers end
findTargets(player, "ixl")
will return every player who has ixl (uppercase, lowercase, doesn't matter) at the start of their name
I can't test this in Studio, so please tell me any errors, and I understand that this may not work.
You could use string.find and check if it returns anything.
if string.find(target) ~= nil then
My name is "BlueTaslem". We could say my 'short name' could be "Blue", but someone might also call me "Taslem".
In that case, my 'short name' is anything that is contained in my name. We can see if a string is contained in another using the find
method:
local name = "BlueTaslem" local lowerName = name:lower() local short = "Taslem" if lowerName:find( short:lower() ) then -- Yes! end
In order to know a name is really referring to someone, it might be a good idea to check that there's only one person that could correspond to (e.g., le
probably isn't enough to know they meant "BlueTaslem" so it might be dangerous to use it)