How to make command strings

Hello everyone and i am making a fighting arena. What i want to be able to do is type in /fight “firstname” “secondname” and then something will happen to those two players. I already have the script down on what to happen to those players i just dont know how i could get the name from a typing event since player names arent the same. Is their a way to test for the first second and third word idivisualy?

I don’t really get what you’re asking, are you asking if you can get multiple names from the command?

If so, you can use string.split()

local testString = "/fight player2 player2 player3"
local args = testString:split(" ")
--The player names are everything in this table with index bigger than one.
--e.g. args[2] is player1

If you are asking of how to find players by writing only the beginning of the name, that’s a bit more complicated.

I would usually make the string lowercase, then loop through all of the players, and get their first (string length) characters in their name and lower it. Then check if their equal, and if so, the player is found

function findPlayer(name)
    for i, plr in pairs(game.Players:GetPlayers()) do --loop through the players.
        name = name:lower() -- make it lowercase
        local testName = (plr.Name):lower():sub(1, #name) --get the lowercase player name with the amount of letters from the name you're looking for.
        if (testName == name) then --If the names are equal
            return plr --return the player you found
        end
    end
end
--Note, I didn't test this in studio, but it should be something similar.

When you get all of the players you can just run whatever you want on them.

3 Likes