Getting Part Of The Message From Chat

So I know with this much of the script, that it would get the full message from the player. How would I get only part of the message that the player says?
Example, in admin commands:

“:re Catherine858”

That command would find the player named “Catherine858” and reset it.

game.Players.PlayerAdded:Connect(function(player)

player.Chatted:Connect(function(msg)


end)

end)
4 Likes

Well in order to check what the message says I’d do

if msg:lower() == "what you want here" then
end

Yea, I know how to check what the message says, the only issue is I want the script to only look at a certain part of the message.

You can split the message using msg:split(" ") and check the 2nd split to get the name

2 Likes

Similar to what @EmbatTheHybrid said you will be using the split method.

With how your doing it with chat It is best to lower all letters in the message.

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local Args = string.split(msg:lower(), " ")
		print(Args[2])
		if Args[2] == "World" then
			print("Continue")
		end
	end)
end)

Let’s say I said, “Hello World” it would print “World” as the second argument in the message.

1 Like

You would use string.split(msg, ' ') to do this, it will return parts of the message in a table.

As others have stated, string.split(string, " ") or string:split(" ") work. If you need a tutorial, I made a whole admin commands tutorial and how to cover making them:

The code you may want to learn from:

msg = string.lower(msg)
local splitString = msg:split(" ") -- makes a table like: {";re", "user"}
local plrName = splitString[2]

someAdminCommand(PersonWhoFiredTheCommand, plrName)