Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Targeting Players without Full Name?

Asked by 8 years ago

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

Log in to vote
1
Answered by
einsteinK 145
8 years ago

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.

0
Thank you so much :) That was the perfect answer! tacktic2010 70 — 8y
0
That would work, but if there are multiple matches, it'd return the first one. GoldenPhysics 474 — 8y
0
Well you could return a table with all found players if you want to. einsteinK 145 — 8y
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 :) tacktic2010 70 — 8y
0
Yeah, only time it would be an issue is if "Someone123" and "Someone12345" are both in-game einsteinK 145 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
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

Answer this question