I'm making an admin script similar to Kohl's admin, and I'm having trouble with this. Currently I have a find player function where I can put in something like "t" and it'll return a player who's name begins with t. As well as "all" returning all players. If something like john,it,ra is given (three names of players), how do I remove the , commas and then run the function with the three names given? I'm not sure if it's something to do with string.match since I've used it before but don't know how to do the function for all three names, or if more are given like y,y,y,y,y
Here's a basic solution:
local str = "builderman, telamon, merely" local Players = {} for name,_ in str:gmatch("[^,]+") do Players[#Players+1] = name:gsub("%s", "") end
Uses a mix of a few examples from the wiki. Including sets, anchors, and quantifiers.
You can run a function with the "Players" table like so:
-- If you have specified parameters. function foo(a, b, c) print(a, b, c) end foo(unpack(Players)) -- If you want to send the table directly. function foo(Players) for _,player in pairs(Players) do print(player) end end foo(Players)