Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Targeting Players without Full Name?

Hey, how would I target a player without using their full name? Eg if I type "kill tack" it will do the same thing as typing "kill tacktic2010"

2 answers

✓ Accepted answer

You could check if the name starts with what you want:

local function FindPlayer(name)
	name = name:lower() -- "AbcGG" becomes "abcgg"
	for k,v in pairs(game:GetService("Players"):GetPlayers()) do
		-- "MrSomebody" becomes "mrsom" if 'name' is 5 characters long
		if v.Name:lower():sub(1,#name) == name then
			return v -- found the player, return it
		end
	end
end

Now you can do FindPlayer("tack") to find Tacktic2010.

5 comments

0

Thank you so much :) That was the perfect answer!

0

That would work, but if there are multiple matches, it'd return the first one.

0

Well you could return a table with all found players if you want to.

0

It isn't very often that people have similar names on roblox, even if they do I can just write out more of the name so it is fine :)

0

Yeah, only time it would be an issue is if "Someone123" and "Someone12345" are both in-game

local function FindPlayer(name)
    name = name:lower() 
    for k,v in pairs(game:GetService("Players"):GetPlayers()) do
        if v.Name:lower():match("^"..name) then
            return v
        end
    end
end

Just for those wondering this is another way of doing it, thanks Pyro! <3

This discussion is preserved as it was. New answers, comments, and votes are closed.