Chat command not working?

I have commands very similar to this that work just fine, so I’m not sure why this doesn’t work. I put the prints in there to see if it would help me find the error better, but none of them print at all when the !shift command is used. No errors shown and NOTHING happens.

Script Variables:

local Group = 14662794
local Replicated = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Remote2 = ServerStorage:FindFirstChild("InfoCommand")
local Remote1 = Replicated:FindFirstChild("DataStore")
local shift = false
local promptcohost = false
local host = false

Shift Command:

	Player.Chatted:Connect(function(Message)
		if Message:lower():sub(1,5) == '!shift' and Player:GetRankInGroup(Group) >= 12 and shift == false then
			print("1")
			local title = "Almost there..."
			local text = "Who is your co-host? Please say their name in the chat and ensure they are in-game."
			game.ReplicatedStorage.RandomNotice:FireClient(Player, title, text)
			promptcohost = true
			host = Player
			print("2")	
		elseif Message:lower():sub(1,5) == '!shift' and Player:GetRankInGroup(Group) <= 12 then
			print("3")
			local title = "⚠️ Error"
			local text = "Sorry, this command is for Restaurant Supervisor+ only!"
			game.ReplicatedStorage.RandomNotice:FireClient(Player, title, text)
			print("4")
		elseif Message:lower():sub(1,5) == '!shift' and shift == true then
			print("5")
			local title = "⚠️ Error"
			local text = "A shift is already in progress!"
			game.ReplicatedStorage.RandomNotice:FireClient(Player, title, text)
			print("6")
		end
	end)
2 Likes

you can just check the message directly.

if Message:lower() == '!shift' and Player:GetRankInGroup(Group) then
4 Likes
Message:lower():sub(1,5) == '!shift'

The reason this didn’t work is because the string’s length is 6. Changing 5 for 6 would have worked.

1 Like