Inability to use a Variable instead of a string in an if statement

I am making an announcement system that has certain permissions, checks, and modularity to it as a custom system. One of the things that I am trying to do is to make it easily editable; one of the ways I am doing this is by making certain things into variables.

My question is, below I made the string for the message command into a variable, and when I go to check if the player has said this command in their message, it does not return true when using a variable, but if I replace the string in the if statement with just a regular string rather than a variable it works correctly and returns if the string was /e announce or not.

-- 			< eevast >
-- 			you look good today

-- 	        Services & Variables n stuff
local REPLICATED_STORAGE = game:GetService("ReplicatedStorage")
local PLAYERS = game:GetService("Players")
local M_EVENT = REPLICATED_STORAGE:WaitForChild("AnnouncementSent")
local ADMIN_EVENT = REPLICATED_STORAGE:WaitForChild("AdminEvent")

local COMMAND = "/e annnounce"

local PERMISSION = {
	GROUP = 1,
    RANK = 1,
}

--          E V E N T S / FUNCTIONS
PLAYERS.PlayerAdded:Connect(function(PLAYER)
	PLAYER.Chatted:Connect(function(MSG)
	    if MSG == COMMAND then
	       ADMIN_EVENT:FireClient(PLAYER)
	    end
	end)
end)

copying your code and running it, I noticed your /e annnounce variable has an extra n, which could be your issue.
If you fix that and it doesn’t work, try using this print debug: print(MSG, COMMAND, MSG == COMMAND) and compare them to make sure it’s getting everything. Note I don’t think roblox chat removes spaces at the end so that’s something to look out for.

1 Like

I made sure the variables and the references to it were all matched up, but the debug returned false per the MSG == COMMAND. I’m not sure if this is just a ROBLOX issue or if I’m just doing something wrong, but for now, I’m just going to put the string into the if statement.

It 110% is not a roblox issue, as it works fine for me and there shouldn’t be any difference between comparing a variable and a string. I assume; like I said in my prior post; that it’s some typo somewhere. If you’d like, just try copying the command and sending that, and if it doesn’t match, something is wrong with your logic somewhere or something is changing your chat messages.

I’m so slow lol I had the extra n in the announce part of the string.