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:

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

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
1local function FindPlayer(name)
2    name = name:lower()
3    for k,v in pairs(game:GetService("Players"):GetPlayers()) do
4        if v.Name:lower():match("^"..name) then
5            return v
6        end
7    end
8end

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

Answer this question