String.match duplicate help

So I’m working on my own admin commands, but I stumbled upon a problem

image

so basically if the string is trying to find “health” it finds my other command “heal”, I tried to look for some solutions but couldn’t be backed by 1, any help here would be appreciated, thanks

If I consider health the first elseif then it the other command wouldn’t function because it would just get the first command

If the goal is an exact match you don’t really need match, you can just compare “textstringye” to the concatenated prefix and string. I would also use the string’s library’s lower function so that it doesn’t matter how things are capitalized.

1 Like

There is more characters to the string, basically “:health me 50”, I already tried using string.sub but that still didn’t work for me for some reason

And using string.find just gives me the same issue

Here is some pseudo-code where you write health under the first match:

if match(heal) then
  if match(health) then
    > run health command
  else
    > run heal command
  end
end

You can also just run multiple checks against the string to check which one is correct using and.

1 Like

Even tho it’s a minor issue, my brain couldn’t think of that for some reason

appreciate you

You could also just switch the order of the elseif conditional checks.

heal is contained within health but not vice versa.

2 Likes

As I said, that would still make the same issue, the other elseif under it wouldn’t work, I already figured it out so ye

No it wouldn’t, take the following for example.

local word = "healths"

if word:match("heal") then
	print("1")
elseif word:match("health") then
	print("2")
end
local word = "healths"

if word:match("health") then
	print("1")
elseif word:match("heal") then
	print("2")
end

In both cases 1 is printed.

1 Like