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

How to shorten a players name?

Hello,

I'm working on an admin system.

In certain commands, an admin can specify a command to work on a particular player. For example ;kill <player>

I wanted to make it so that the admin wouldn't have to specify the entire player name they wanted to effect. For example, for me, instead of having to do ;kill Tweakified, you could do ;kill Twea

How would this be achieved?

I thought of using :match to do this. However, running ;kill ified would also work.

Any advice/help you can give would be appriciated.

2 comments

0

Yes, thats what I tried using, however if I used ;kill ified, it still works

3 answers

After doing some additional research, I found a solution to my problem:

From this

I was able to modify the code to check only the start of the string with using the ^ This is how I modified the code:

local function GetPlayerFromString(nameString)
    local matches= {}
    for _, player in ipairs (game.Players:GetPlayers()) do
        if string.lower(player.Name):match("^".. string.lower(nameString)) then
            table.insert(matches, player)
        end
    end
    if #matches== 1 then
        return matches[1]
    else
        return nil
    end
end

Hope this helps someone in the future, Tweakified

2 comments

0

make sure to mark this question as answered

0

You can't mark your own answer to your own question as answered

I don't think that this type of thing is even possible. You need to put the Full Player's Username, as Lua it's Case Sensitive.

1 comment

0

It is possible did u even read his question he said how to shorten names like in an admin game.

I'm conveniently doing the same thing. Here's my method:

local Players = game:GetService'Players';
local function GetPlayerFromSubString(Name)
	Name = Name:lower():reverse();
	for _,a in pairs(Players:GetPlayers())do
		local b = (a.Name):lower():reverse();
		if string.find(b,Name,#b-#Name)then -- Note: #(string) is the same as string.len
			return a;
		end;
	end;
end;

1 comment

0

Nice, thats an interesting way of doing it!

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