How to get a specific part of a string?

Hello,

I have a spell system which users chat then executes the script. There’s a spell I have which consists of the spell name with a username at the end. How would I do so I get the username, considering they give something like.
inveniet hostium et teninbre uhi
Notice how at the end it’s spelled uhi which is what I’m trying to get but is different depending on which user you want.

If I try to subtract inveniet hostium et teninbre from the string, then there would be the rest of the stuff chatted by the user.
Example: inveniet hostium et teninbre uhi bla bla bla

Thanks!

do something like this:

local args = string.split(msg, " ") --change msg to the name of the string you are trying to get the player from
local player = args[#args]
print(player)

You can use string.gsub("inveniet hostium et teninbre uhi", "inveniet hostium et teninbre ", "") which then eliminates the whole phrase leaving you the player name that was supplied. Here is the API Reference for string.

Thanks! @sniper74will
Would there be another way than using string.split?

@COUNTYL1MITS that’s not what I wanted but thanks anyways, still help. Since in case the user chats an extra word at the which would bother the whole process.

there isn’t any other way you can really get the player from that as far as I know. string.split just gives a dictionary/array of the words in the string (splitting it based on what the 2nd parameter is).
Edit: string.find would work, but it would be more of a bother that string.split.