Hey everyone,
I’ve recently been working on an admin system, and I was wondering if there is a good way to make an argument to reference multiple players but split them using a comma.
Thanks in advance if you help, I’ll be happy to answer any questions.
local Players = game:GetService("Players")
local function getPlrsFromNameString(stringWithNames)
local plrs = {}
for i, s in ipairs(stringWithNames:split(",")) do
local name = s:match("%S") -- non whitespace characters
local plr = Players:FindFirstChild(name)
if plr then
plrs[#plrs+1] = plr
else print("No player found with name "..name)
end
end
return plrs
end
@RoBoPoJu I tested the code and I got one error in Players:FindFirstChild(Name). It’s a W000: Mismatch number and string error. Here’s my code:
elseif Key:find(",") then
Key = Key:sub(1,#Key)
local function getPlrsFromNameString(stringWithNames)
for i, s in pairs(stringWithNames:split(",")) do
local name = s:match("%S")
local plr = Players:FindFirstChild(name) -- Error here
if plr then
Players[#Players+1] = plr
end
end
end
else