Check if a player argument is inside a string (read desc.)

  1. What do you want to achieve? Keep it simple and clear!
  • I want to achieve a way to check if a certain word is inside my list of pre-made command aliases
  1. What is the issue? Include screenshots / videos if possible!
  • I’m aware of %s but it doesnt seem to fit my needs for this particular issue
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
  • Searching it up on google and experimenting in-studio

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

antibreakcmd = {
	"ayo, teleport %s here",
	"ayo, tp %s to me",
	"ayo, please bring %s over here"
}

So above me is a piece of code that I want to implement for my command. I wanna somehow check if the command is equal to any of the above aliases. And for that I will need to have something that tells the code that the chat message is equal to any of the cmd aliases. Example:

Example

Let’s say someone typed:

[Any Admin]: ayo, teleport PLAYER to me

this would teleport PLAYER to the admin. I already have a function for teleporting the player btw, and checking if the string is correct although not with the player argument implemented. Here is the script btw:

Check if the command matches with the chat string
function CheckCmd(msg, Type, user)
	print(msg) -- message from user
	print(user) -- user who send message
	print(Type) -- the list of command aliases
	for _, correct in ipairs(Type) do
		print(correct)
		if msg == correct then
			return true
		end
	end
	return false
end
Command format if u need it

And also this:

	if CheckCmd(msg, antibreakcmd, speaker) then --Chat Command
	--My teleport script is in here.
    end
	

Sincerely,
Dev_Mathe

if you want to find a string in another string, maybe use string.find()

print(string.find(string1, string2));
1 Like

I don’t know if that would be a bit difficult to implement as the other commands don’t require an argument. I’ll try anyways : )

Why not just use FindFirstChild

local Player = Players:FindFirstChild(String1)
if not Player then return end;
print(Player)

it might work, but I have decided to just give up on this and make something else related. Thank you for the help though :slight_smile:

I’ll just mark this as the solution