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

How to make admin commands find player from incomplete username?

So I have an admin command script, it works fine, but its a pain typing out the entire username of a player to do a command, I want the effect admin scripts such as Kohl's have, where a player can be found just from the start of their username

local function findplayer(name)
	for _,player in pairs(game.Players:GetPlayers()) do
		if string.lower(player.Name) == name then
			return player
		end
	end
	return nil
end

This is the current function that finds the player, anyone know how I can edit it to make this possible?

2 answers

✓ Accepted answer
local function findplayer(name)
    for _,player in pairs(game.Players:GetPlayers()) do
        if string.find ( string.lower(player.Name), name) then
            return player
        end
    end
    return nil
end

1 comment

0

Thanks! this did the job

You would use string.match().

local function findplayer(name)
    for _,player in pairs(game.Players:GetPlayers()) do
	local plr = string.lower(player.Name)
        if string.match(name, plr) then
            return player
        end
    end
    return nil
end

1 comment

0

I wasn't aware of that, thanks. Still didn't fix it unfortunately

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