Attempt 2, first one was closed. so this time I will be more concrete.
lets say someone chatted this:
/w Felicia OMG YOU NOOB!
/w- Option To Send Private Message
Felicia- The Receivers Name
OMG YOU NOOB! - The Message
Event:FireClient(Player, Message)
How to I Get Player and message from the string?
Btw give me a WARNING before closing it.
I've gotten this so far -
game.Players.PlayerAdded:connect(function(Player) Player.Chatted:connect(function(Message) if string.sub(Message, 1,2) == "/w" then end end) end)
String patterns hold the secret of the universe
You may be looking to do something like this
local Target, Message = msg:match('^/w%s+(%w+)%s+(.*)$')
Let's break that down
^
is the matching anchor for the start of the string.
/w
has nothing special about it, it's to match your /w.
%s
is the set for white space characters.
+
is the greedy modifier that tells it to match the preceding set 1+ times.
%w
is the set for letters and numbers.
()
is the capture. You'll want to google Lua pattern captures.
.
is the wildcard and matches everything.
*
is the modifier that matches 0+ occurrences of a set, as many times as possible.
$
is the anchor for the end of the string.
Help
Well you are going the right spot what I would do though is make a table for each space, this way you can catagorize the command to the player to any other groups after that for advanced admin commands like kohls or something liek tht
text = "/w Felicia OMG U NOOB" wordlist = {} for word in text:gmatch("[^" .." ".. "]+") do -- seperates names by a , table.insert(wordlist, word) end
printing out the table namelist thru a iterator would print out
/w Felicia OMG U NOOB
aak