Why is this script teleporting me even when not fully chatting the intended word?

I have this script where when you type a specific message in chat it should teleport you to a specific part that I have positioned somewhere (the script is in ServerScriptService), but for some reason even if I say one letter from the actual word it still teleports me, I want it to only teleport if you say the whole thing in chat exactly as I wrote it in the script, how do I fix this issue?

Example: The player is supposed to chat “INSANE OBBY!!!” in chat for it to work, but even if the player chats “ins” or “o” or “obby” or any letter from the word it still teleports him.

Current script:

local partToTp = game.Workspace.InsObbyTP
local DesiredMessage = "INSANE OBBY!!!"
local players = game:GetService('Players')

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if string.find(string.lower(DesiredMessage),string.lower(message)) then
			player.Character:PivotTo(partToTp.CFrame)
		end
	end)
end)

Change this

if string.find(string.lower(DesiredMessage),string.lower(message))

To this

if string.lower(DesiredMessage) == string.lower(message)
2 Likes

@msix29’s code explained:

The string.find checks if a pattern-string is within the given string.
example:

string.find("Hello", "He") -- pattern "He" is in string "Hello" 

That means that you only need a part of the actual string.
However by using == you are checking if both strings are equal.

Small tip:
instead of string.lower(message) you can also write message:lower() as it’s 100% a string. Same applies for DesiredMessage.

1 Like

Thank you very much to the both of you!!