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

How can I make a kick script without the full name of the player?

I was looking at the questions a bit, but none of the answers worked for me. what I want is to make a script that some administrators, allowed users that I can add in a variable like: local Admins = {"nanitook", "anotherPlayer"}, can kick a player with the command ";kick player" but without typing the player's full name.

2 comments

0

Pretty sure its string.match, maybe not, just due to me not scripting roblox in a while.

0

substring lets you get part of the user's name, which you can compare to your partial name and kick the player if they match

1 answer

✓ Accepted answer

You can use string.find for this.

local Players = game:GetService(“Players”)

local function PlayerSearch(String)
    String = string.lower(String)
    local List = Players:GetPlayers()
    for _, Player in pairs(List) do
        local Name = string.lower(Player.Name)
        if string.find(Name, String) then
            return Player
        end
    end
end

An example of using the function: Say I’m in the game. My username is ThatPreston.

local Preston = PlayerSearch("Preston") -- > game.Players.ThatPreston

ROBLOX just left the game.

local Roblox = PlayerSearch("Blox") -- > nil

ROBLOX just joined the game.

Roblox = PlayerSearch("Blox") -- > game.Players.ROBLOX

I hope this helped you. Good luck!

2 comments

0

Thanks, it works!

0

keep in mind that thisll return the first player whos name contains the string PlayerSearch("SOME STRING"). If you have players named erik.cassel and erik.casselRIP, and you searched for the name 'erik' you'd get whichever player the code looks at first

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