Issues with string.find()

Why will this not work? It is indexing through a table of spell names but string.find wont work :thinking:

  function onChatted(msg, speaker)
local loaded = false
local source = string.lower(speaker.Name)
print("Chatted")
for SaidSpell = 1, #Spells do
	if (string.find(msg, SaidSpell) ~= nil) then
		print("Spell was found", SaidSpell)
		Mode = SaidSpell.Value
		CurrentSpell = SaidSpell
	  end
     end
   end

SaidSpell is a number and you’re searching for it in a string like it’s a string, and then you’re trying to read Value from it like it’s an object. This is a numerical for loop, so you might want to have for index = 1, #Spells do SaidSpell = Spells[index] or for _, SaidSpell in pairs(Spells) do and then use string.find(msg, SaidSpell.Value) if it’s actually an object and not a string.

2 Likes

Thankyou, yeah i changed it to:

for SaidSpell,SpellValue in pairs(Spells) do
  Other stuff-------
end

that seemed to work :slight_smile: