✓ Accepted answer
#What you need
You're on the right track. In order to pick apart the player's chat, you need to use string patterns.
String patterns are exactly what they sound like - ways to detect patterns in strings.
##Getting the recipient
You want to detect the recipient, proceeding the "/pay " command. The pattern for this would be .+%s - i'll break down why:
. stands for any character, since player's names can be most characters.
+ stands for consecutive matches of the preceding pattern.
%s stands for a space.
You can use this patern to detect who you are paying to. Note - it will be inclusive of the space, so you'll have to omit it using string.sub.
local recipientPattern = ".+%s"
function onChatted(message, player)
local filteredText = game.Chat:FilterStringForBroadcast(message,player)
if filteredText:sub(1,5) == "/pay " then
local recipient = filteredText:sub(6):match(recipientPattern)
recipient = recipient:reverse():sub(1):reverse()
print(recipient);
end
end
##Getting the amount
Now that you have the recipient, you can move onto getting the amount. Use the string.len function, along with the string.sub function to omit the recipient from the string. Then, use the %d+ string pattern to detect integers in the string.
local recipientPattern = ".+%s"
local amountPattern = "%d+"
function onChatted(message, player)
local filteredText = game.Chat:FilterStringForBroadcast(message,player)
if filteredText:sub(1,5) == "/pay " then
local recipient = filteredText:sub(6):match(recipientPattern);
recipient = recipient:reverse():sub(1):reverse()
print(recipient);
local amount = filteredText:sub(recipient:len()+6):match(amountPattern)
print(amount);
end
end
2 comments
That's how you do it. e-e Also, you could use set up a function to get the selected player; take Person299 and Kohltastrophe's Admin Commands as references.
I want to add a number after and I don't know how to distinguish a username from the number