Pass/Fail Command Not Working

I am working on a system that I will be releasing to the public once it is done.
However, I have hit a bump.
My script is not working.
I am trying print debugging, but nothing printed.

local groupID = 4881614 -- Change to your group ID
local minRankToHost = 6 -- Change to the minimum rank ID that is allowed to host sessions.
local minRankToPassAndFailUsers = 4 -- Change to the minimum rank allowed to pass/fail users.

game.Players.PlayerAdded:Connect(function(player)
	local status = Instance.new("StringValue", player)
	status.Name = "Status"
	status.Value = ""
end)

local failCommand = "!fail "
local passCommand = "!pass "

function onChatted(msg, recipient, speaker, arguments) 

local source = string.lower(speaker.Name)
msg = string.lower(msg)

	if (msg == "!session start") then
		if speaker:GetRankInGroup(groupID) >= minRankToHost then
			game.ReplicatedStorage.Session:FireAllClients("Start", source)
		end
	elseif (msg == "!session end") then
		if speaker:GetRankInGroup(groupID) >= minRankToHost then
			game.ReplicatedStorage.Session:FireAllClients("End", source)
		end
	elseif (msg == "!pass ") then
		if speaker:GetRankInGroup(groupID) >= minRankToPassAndFailUsers then
			local passedUser = msg:sub(passCommand:len() + 1)
			
			print(passedUser)
			
		end
	elseif (msg == "!fail ") then
		if speaker:GetRankInGroup(groupID) >= minRankToPassAndFailUsers then
			
			print("Fail command received")
			
			local failedUser = msg:sub(failCommand:len() + 1)
			
			print(failedUser)
			
		end
	
	
	end 

end 


function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

I used this article to get the argument (the player) but it did not work.

You do have a couple of arguments in there that are known to be deprecated (1 being the Chatted Recipent’s Event), could you try this maybe?

local groupID = 4881614 -- Change to your group ID
local minRankToHost = 6 -- Change to the minimum rank ID that is allowed to host sessions.
local minRankToPassAndFailUsers = 4 -- Change to the minimum rank allowed to pass/fail users.
local failCommand = "!fail "
local passCommand = "!pass "

game.Players.PlayerAdded:Connect(function(player)
    print("Player added: ", player.Name)

    local Status = Instance.new("StringValue")
    Status.Name = "Status"
    Status.Value = ""
    Status.Parent = player

    player.Chatted:Connect(function(msg)
        local source = string.lower(player.Name)
        local msg = string.lower(msg)

        print("Message: "..msg)
        print("Source: "..source)

        if player:GetRankInGroup(groupID) >= minRankToPassAndFailUsers then
            if msg == passCommand then
                print("User Passed")
                local passedUser = msg:sub(passCommand:len() + 1)
            
                print(passedUser)
            elseif msg == failCommand then
                print("User Failed")
                local failedUser = msg:sub(failCommand:len() + 1)
            
                print(failedUser)
            end
        end

        if player:GetRankInGroup(groupID) >= minRankToHost then
            if msg == "!session start" then
               print("Session Starting")

               game.ReplicatedStorage.Session:FireAllClients("Start", source)
            elseif msg == "!session end" then
               print("Session Ending")
               game.ReplicatedStorage.Session:FireAllClients("End", source)
            end
        end

    end)
end)

Ok!

Result:
Success.

Whats next?

When you mean “Success”, do you mean the code successfully works? :thinking:

Yes.
The code works.
It printed the following:

Well if that’s the case, shouldn’t you mark the post as a solution then? Unless if you have anymore issues you need to address here?

Oh wait it didn’t print the player that failed/passed.

Did you get any errors on your Output at all?

No, I did not get any errors. :confused:

I think I found the issue & I edited my post, could you try it again?

Yes, testing…

Result:

Failed

O k a y
Maybe it’s cause the order it’s in? I added a couple of more print statements to hopefully debug where the issue could lie

Ok!
What am I looking for to see if it worked?

Briefly check if the failCommand/passCommand conditional statements work, and if they print out the results

I will send you a screenshot of what was printed out when I ran the command.

@Jackscarlett you there???

Fixed by myself.
The error was using

msg == "!pass"

I should have been using

string.sub