I’m trying to make a admin script starting by detecting the prefix and detecting if i said one or more of the starter letters of a player in the game, hope someone can explain me.
I might be overcomplicating it but this is how I’d approach it probably, haven’t tried it but I added comments incase it errors:
local players = game:GetService('Players')
local localPlayer = players.LocalPlayer
local prefix = '/findplayer'
localPlayer.Chatted:Connect(function(message)
if message:lower():sub(1,prefix:len()) == prefix then
-- the prefix matches, so let's move to the next step:
local args = message:split(' ') -- this splits our message by the spaces which would indicate different arguments
local playerArgument = args[2] -- the player argument is the second word, the word after the /findplayer prefix
local possiblePlayers = {}
for i,player in ipairs(players:GetPlayers()) do
if player.Name:lower():sub(1,playerArgument:len()) then
table.insert(possiblePlayers, player.Name) -- if it matches the prefix we gave, add the player to the array
end
end
if #possiblePlayers == 1 then -- one player was found
print('Found',possiblePlayers[1])
elseif #possiblePlayers > 1 then -- multiple players were found
print('Found several players',table.concat(possiblePlayers, ', ')
else -- no players were found
print('Found no players!')
end
end
end)
1 Like
How is GetChildren() or Chatted relevant to the thread?