Changing a UserInput Script

Hello,
I have this script below which whitelists who can trigger a function with the KeyCode T. This script works, however there are a few issue.

  1. When players type in the Roblox chat something with “t,” the function activates.

Can someone help me alter this script so this problem is fixed?

UserInputService.InputBegan:Connect(function(Key)
	if Player.Team == game.Teams["On-Duty"] then
		if Key.KeyCode == Enum.KeyCode.T then
			ChangeActive()
		end
	end
end)

EDIT: I found out how to team-lock it. Still having the Roblox chat issue.

Consider using ContextActionService and utilize the BindAction function.

If something else acts on the input, it will not fire.

local function handleAction(actionName, inputState, inputObject)
	if actionName == "T" then
		if Player.Team == game.Teams["On-Duty"] then
             ChangeActive()
        end
	end
end

ContextActionService:BindAction("T", handleAction, false, Enum.KeyCode.T)

Lmk if there are any errors, not tested.